Skip to content

Commit

Permalink
unsure what i did here. something about joining models in a query i g…
Browse files Browse the repository at this point in the history
…uess
  • Loading branch information
jonerer committed Oct 18, 2024
1 parent 5515cbb commit 525bcbc
Show file tree
Hide file tree
Showing 92 changed files with 1,009 additions and 20 deletions.
12 changes: 12 additions & 0 deletions experiments/jsdoctest/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {getUser} from "./lib.mjs";


/**
* @returns {User}
*/
function myUser() {
const us = getUser("hej")
return us
}

console.log(myUser.prototype.id)
20 changes: 20 additions & 0 deletions experiments/jsdoctest/lib.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* @typedef {Object} User
* @property {number} id
* @property {string} name
* @property {string} email
*/
export class User {
constructor(id, name, email) {
}
}

/**
* @param {number} id
* @returns {User}
*/
export function getUser(id) {
return new User({
id
})
}
Empty file.
Empty file.
Empty file added experiments/sem2/app/shape.yaml
Empty file.
Empty file added experiments/sem2/fw/index.ts
Empty file.
8 changes: 8 additions & 0 deletions semla/decl/appinfo.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export function setAppBasedir(dir: any): void;
export function getFwPackageDir(): string;
export function getFwBasedir(): string;
export function getRelativeImport(from: any): string;
export function getAppBasedir(): string;
export function getAppMigrationsDir(): string;
export function isNonProd(): boolean;
export function isNonTest(): boolean;
3 changes: 3 additions & 0 deletions semla/decl/authentication/authenticators.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function registerAuthenticator(authenticator: any): void;
export function getAuthenticator(name: any): any;
export function getAuthenticatorForRoute(generatedRoute: any): any;
1 change: 1 addition & 0 deletions semla/decl/client/devbundler.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function initDevBundler(): Promise<void>;
15 changes: 15 additions & 0 deletions semla/decl/config/config.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export default function get(path: any, _default: any): any;
export function add(path: any, value: any): void;
export function addDefault(path: any, value: any): void;
export function envShortName(): "dev" | "test" | "prod";
export function addItemToObject(object: any, path: any, content: any): any;
export function getLeaves(obj: any, path?: string, collector?: {}): {};
export function fullConf(): {};
export function fullDefaults(): {};
export function setConf(_conf: any): void;
export function setDefaults(_defaults: any): void;
export function allWithResolution(): {
conf: {};
defaults: {};
resolved: {};
};
1 change: 1 addition & 0 deletions semla/decl/config/defaults.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function applyDefaultConfig(): void;
14 changes: 14 additions & 0 deletions semla/decl/controllers/setup.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export function registerController(controller: any): void;
export function getControllers(): {
name: string;
propertyNames: string[];
}[];
export class ControllerSetupCollector {
constructor(controller: any);
controller: any;
middlewares: any[];
before(actions: any, callback: any): void;
getRelevantMiddleware(action: any): any[];
}
export function runMiddleware(controllerInst: any, action: any, ctx: any): Promise<void>;
export function getController(name: any): any;
12 changes: 12 additions & 0 deletions semla/decl/db/adapters.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export class DbAdapter {
getModelTableMetadata(): void;
}
export class PostgresDbAdapter extends DbAdapter {
typeIdToString(tableName: any, name: any, dataTypeId: any): "BOOL" | "BIGSERIAL" | "INTEGER" | "REAL" | "TEXT" | "VARCHAR" | "TIMESTAMP" | "TIMESTAMPTZ" | "DECIMAL";
}
export class MockDbAdapter extends DbAdapter {
metas: {};
allEmpty: boolean;
addModelTableMetadata(modelName: any, metas: any): void;
setAllEmpty(): void;
}
2 changes: 2 additions & 0 deletions semla/decl/db/ar.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export function instantiateFromDbRow(model: any, row: any): any;
export function addARQueryThings(model: any): void;
3 changes: 3 additions & 0 deletions semla/decl/db/db.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function getPool(env: any): any;
export function query(text: any, params: any, env: any): Promise<any>;
export function close(): Promise<void>;
12 changes: 12 additions & 0 deletions semla/decl/db/descriptiongen.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ModelType } from './models';
import { Field } from './querying/fields';
export declare function findStartEnd(definingFile: string, model: ModelType): {
start: number;
end: number;
};
export declare function lineForField(field: Field): [string, string, string, string];
export declare function generateComment(model: ModelType, newlineChar: string): Promise<string>;
export declare function insertComment(original: string, start: number, end: number, content: string): string;
export declare function generateNewContent(contentBefore: string, model: ModelType): Promise<string>;
export declare const modelsToGenerateDescriptionsFor: () => ModelType[];
export declare const generateDescriptions: () => Promise<void>;
72 changes: 72 additions & 0 deletions semla/decl/db/migrations/collector.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
interface FieldOptions {
null?: boolean;
default?: any;
}
interface TableObject {
name: string;
}
declare abstract class MigrationField {
protected name: string;
protected options?: FieldOptions;
type: string;
constructor(name: any, options: any);
nullableString(): "" | " NOT NULL";
abstract ddl(param: TableObject): any;
}
export declare class MigratorTable {
private fields;
name: string;
constructor(name: string);
integer(name: any, options?: FieldOptions): void;
bigint(name: any, options?: FieldOptions): void;
text(name: any, options?: FieldOptions): void;
bool(name: any, options?: FieldOptions): void;
boolean(name: any, options?: FieldOptions): void;
timestamp(name: any, options?: FieldOptions): void;
timestamptz(name: any, options?: FieldOptions): void;
decimal(name: any, options?: FieldOptions): void;
timestamps(): void;
generateDDL(): string;
}
declare class FieldCollector {
type: any;
tableName: any;
fields: MigrationField[];
constructor(type: any, tableName: any);
bool(name: any, opts: FieldOptions): void;
boolean(name: any, opts: FieldOptions): void;
text(name: any, opts: FieldOptions): void;
integer(name: any, opts: FieldOptions): void;
timestamp(name: any, opts: FieldOptions): void;
timestamptz(name: any, opts: FieldOptions): void;
decimal(name: any, options?: FieldOptions): void;
generateDDL(): string;
}
declare abstract class TableOperation {
tableName: string;
constructor(tableName: any);
abstract ddl(): any;
}
export declare class AlterTable {
private field;
operations: TableOperation[];
add: FieldCollector;
tableName: any;
constructor(table: any);
rename(from: any, to: any): void;
dropColumn(name: any): void;
generateOperationDDLs(): string;
ddl(): string;
}
export declare class MigrationCollector {
private rawQueries;
private tables;
private alterTables;
constructor();
query(text: string): void;
alterTable(name: string, cb: (t: AlterTable) => void): void;
renameTable(nameBefore: string, nameAfter: string): void;
addTable(name: string, cb: (t: MigratorTable) => void): void;
generateStatements(): string[];
}
export {};
15 changes: 15 additions & 0 deletions semla/decl/db/migrations/migration.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export function addMigrationFileDir(dir: any): void;
export function getMigrations(env: any): Promise<MigrationFile[]>;
export function forceRunMigrationClass(cls: any): Promise<any>;
export function getStatements(cls: any): Promise<string[]>;
export function runMigrations(env: any): Promise<{
success: boolean;
message: string;
numSuccessful: number;
}>;
declare class MigrationFile {
fullpath: string;
name: string;
hasRun: boolean;
}
export {};
38 changes: 38 additions & 0 deletions semla/decl/db/models.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Field, Fields } from './querying/fields';
import { ValidationCollector } from './validation/collection';
import { ModelSetupCollector } from './models/collector';
export interface ModelType {
id: Field;
_fields: Fields;
_relationFields: Field[];
_modelName: string;
prototype: any;
_routeParamName: string;
_setup: ModelSetupCollector;
_tableName: string;
_validations: ValidationCollector;
_loaded: boolean;
_registeringPath: string;
loaded(): boolean;
findOne(any: any): any;
find(any: any): any;
}
interface ModelsType {
[s: string]: ModelType;
}
export interface ModelInstance {
}
export declare const assureBucket: (obj: any) => void;
export declare function setDbAdapter(adapter: any): void;
export declare const registerModelsAsQueryParams: (app: any) => Promise<void>;
export declare const modelNameToTableName: (name: any) => any;
export declare const getLowercasedModel: (name: any) => ModelType | undefined;
export declare const collectSetup: (model: any) => void;
export declare const prepareModels: () => Promise<void>;
export declare const models: ModelsType;
export declare function registerModel(model: any): void;
export declare function clearModels(): void;
export declare function getUserModels(): ModelsType;
export declare function getLoadedUserModelList(): ModelType[];
export declare function getModels(): ModelsType;
export {};
27 changes: 27 additions & 0 deletions semla/decl/db/models/collector.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { ValidationCollector } from '../validation/collection';
import { ModelType } from '../models';
export interface CollectedRelation {
type: 'belongsTo' | 'hasMany';
name: string;
options: any;
model: ModelType;
}
export interface BelongsToOptions {
model?: string;
}
export interface HasManyOptions {
model?: string;
}
export declare class ModelSetupCollector {
relations: CollectedRelation[];
fillable_fields: string[];
model: ModelType;
validationCollector: ValidationCollector;
_getFromParamCallback: (id: any) => string;
constructor(model: ModelType);
belongsTo(name: any, options?: BelongsToOptions): void;
fillable(fields: any): void;
getFromParam(callback: any): void;
hasMany(name: any, options?: HasManyOptions): void;
validate(callback: (validations: ValidationCollector) => void): void;
}
31 changes: 31 additions & 0 deletions semla/decl/db/querying/fields.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { ModelType } from '../models';
export declare const jsifyFieldName: (underscored_name: any) => string;
export declare const dbIfyJsName: (jsName: any) => any;
declare type FieldTypes = 'hasMany' | 'belongsTo';
export declare class Field {
dbName: string;
jsName: string;
type: FieldTypes;
relation: boolean;
targetModel?: ModelType;
model: ModelType;
tsType: string;
relationField?: Field;
isLessThanComparable(): boolean;
static typeStringToTsType(string: any): "Date" | "number" | "string" | "boolean";
static FromDb(dbName: any, type: any): Field;
static FromRelation(relation: any): Field;
jsIfy(dbName: any): string;
isDateTime(): boolean;
}
export declare class Fields {
private all;
constructor(arr: any);
getAll(): Field[];
dbFieldNames(): string[];
jsFieldNames(): string[];
addField(field: any): void;
getByJsName(changedJsName: any): Field | undefined;
getByDbName(column: any): Field | undefined;
}
export {};
48 changes: 48 additions & 0 deletions semla/decl/db/querying/queryBuilder.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { ModelInstance, ModelType } from '../models';
import { Field } from './fields';
declare type SqlOperators = '=' | '!=' | '<' | '<=' | '>' | '>=' | 'ANY';
export declare class QueryField {
private field;
model: ModelType;
private name;
dbName: any;
private operator;
relation?: Field;
constructor(model: ModelType, field: Field, operator: SqlOperators);
setRelation(rel: any): void;
needsIdx(value: any): boolean;
sql(alias: any, value: any, paramId: any): string | undefined;
}
export declare class QueryBuilder {
private conditions;
private joinFields;
private aliases;
private orderings;
private limitCount;
private model;
constructor();
joinedColumnNames(): string;
leftJoin(...conditions: any[]): this;
join(...conditions: any[]): this;
isJoinedWith(relation: any): boolean;
isAliasAvailable(str: any): boolean;
setUpAliases(): void;
getAlias(model: any): string;
joinTablesString(): string;
conditionsString(values: any): string;
sql(): (string | never[])[];
limitStr(): string;
orderingStr(): string;
first(): Promise<ModelInstance>;
one(): Promise<ModelInstance>;
query(): Promise<ModelInstance[]>;
all(): void;
get(): Promise<ModelInstance[]>;
targetModel(model: any): void;
addConditions(conditions: any): void;
addCondition(param: any): void;
order(param: any, direction: any): this;
limit(count: any): this;
where(...args: any[]): this;
}
export {};
2 changes: 2 additions & 0 deletions semla/decl/db/querying/relations.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { ModelType } from '../models';
export declare const setupRelations: (model: ModelType) => void;
1 change: 1 addition & 0 deletions semla/decl/db/querying/utils.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function findOneSql(model: any, id: any): (string | never[])[];
10 changes: 10 additions & 0 deletions semla/decl/db/serialization.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export declare const registerSerializer: (serializer: any) => void;
export declare class SerializerCollector<T> {
fieldsToResolve: string[];
objsGiven: {};
fieldsToStringify: string[];
constructor();
add(...args: object[] | (keyof T)[]): void;
addString(obj: keyof T | (keyof T)[]): void;
}
export declare const serialize: (hej: any, desiredSerializer?: string | undefined) => Promise<any>;
3 changes: 3 additions & 0 deletions semla/decl/db/sessions/db_session.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function register(): void;
export function getDbStore(expSess: any): any;
export function hasSessionsTable(): Promise<boolean>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default class Migration_20200326_2122_AddSessionsTable {
change(m: any): void;
}
16 changes: 16 additions & 0 deletions semla/decl/db/typegen.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { ModelType } from './models';
interface Attributes {
settableName: string;
settableContent: string;
attributesName: string;
attributesContent: string;
joinableFieldsName: string;
joinableFieldsType: string;
queryFieldsName: string;
queryFieldsContent: string;
}
export declare const generateAttributesForModel: (model: ModelType) => Attributes;
export declare const generateBaseClassForModel: (model: ModelType, attributes: Attributes) => string;
export declare const generateBodyForModel: (model: ModelType) => string;
export declare const generateTypes: () => Promise<void>;
export {};
Loading

0 comments on commit 525bcbc

Please sign in to comment.