appflare 0.2.14 → 0.2.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli/schema-compiler.ts +104 -8
- package/cli/templates/dashboard/builders/table-routes/helpers.ts +1 -5
- package/cli/templates/handlers/generators/types/query-definitions/schema-and-table-types.ts +23 -19
- package/cli/utils/schema-discovery.ts +1 -1
- package/dist/cli/index.js +179 -175
- package/dist/cli/index.mjs +179 -175
- package/dist/index.d.mts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
- package/schema.ts +19 -2
package/dist/index.d.mts
CHANGED
|
@@ -115,6 +115,8 @@ type RelationManyOptions = {
|
|
|
115
115
|
type ColumnReference = {
|
|
116
116
|
table: string;
|
|
117
117
|
column: string;
|
|
118
|
+
onDelete?: ForeignKeyAction;
|
|
119
|
+
onUpdate?: ForeignKeyAction;
|
|
118
120
|
};
|
|
119
121
|
type ColumnDefinition = {
|
|
120
122
|
kind: "column";
|
|
@@ -198,7 +200,7 @@ declare class ColumnBuilder {
|
|
|
198
200
|
* a runtime default of `new Date()`.
|
|
199
201
|
*/
|
|
200
202
|
defaultNow(): ColumnBuilder;
|
|
201
|
-
references(table: string, column?: string): ColumnBuilder;
|
|
203
|
+
references(table: string, column?: string, actions?: Pick<ColumnReference, "onDelete" | "onUpdate">): ColumnBuilder;
|
|
202
204
|
toDefinition(): ColumnDefinition;
|
|
203
205
|
}
|
|
204
206
|
declare function table(shape: TableShape, options?: TableOptions): TableDefinition;
|
|
@@ -206,6 +208,7 @@ declare function schema(tables: Record<string, TableDefinition>): SchemaDefiniti
|
|
|
206
208
|
declare function isSchemaDefinition(value: unknown): value is SchemaDefinition;
|
|
207
209
|
declare const v: {
|
|
208
210
|
int: (options?: ColumnBuilderOptions) => ColumnBuilder;
|
|
211
|
+
number: (options?: ColumnBuilderOptions) => ColumnBuilder;
|
|
209
212
|
string: (options?: ColumnBuilderOptions) => ColumnBuilder;
|
|
210
213
|
boolean: (options?: ColumnBuilderOptions) => ColumnBuilder;
|
|
211
214
|
date: (options?: ColumnBuilderOptions) => ColumnBuilder;
|
package/dist/index.d.ts
CHANGED
|
@@ -115,6 +115,8 @@ type RelationManyOptions = {
|
|
|
115
115
|
type ColumnReference = {
|
|
116
116
|
table: string;
|
|
117
117
|
column: string;
|
|
118
|
+
onDelete?: ForeignKeyAction;
|
|
119
|
+
onUpdate?: ForeignKeyAction;
|
|
118
120
|
};
|
|
119
121
|
type ColumnDefinition = {
|
|
120
122
|
kind: "column";
|
|
@@ -198,7 +200,7 @@ declare class ColumnBuilder {
|
|
|
198
200
|
* a runtime default of `new Date()`.
|
|
199
201
|
*/
|
|
200
202
|
defaultNow(): ColumnBuilder;
|
|
201
|
-
references(table: string, column?: string): ColumnBuilder;
|
|
203
|
+
references(table: string, column?: string, actions?: Pick<ColumnReference, "onDelete" | "onUpdate">): ColumnBuilder;
|
|
202
204
|
toDefinition(): ColumnDefinition;
|
|
203
205
|
}
|
|
204
206
|
declare function table(shape: TableShape, options?: TableOptions): TableDefinition;
|
|
@@ -206,6 +208,7 @@ declare function schema(tables: Record<string, TableDefinition>): SchemaDefiniti
|
|
|
206
208
|
declare function isSchemaDefinition(value: unknown): value is SchemaDefinition;
|
|
207
209
|
declare const v: {
|
|
208
210
|
int: (options?: ColumnBuilderOptions) => ColumnBuilder;
|
|
211
|
+
number: (options?: ColumnBuilderOptions) => ColumnBuilder;
|
|
209
212
|
string: (options?: ColumnBuilderOptions) => ColumnBuilder;
|
|
210
213
|
boolean: (options?: ColumnBuilderOptions) => ColumnBuilder;
|
|
211
214
|
date: (options?: ColumnBuilderOptions) => ColumnBuilder;
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var l=class n{definition;constructor(e,i={}){if(typeof e=="string"){this.definition={kind:"column",type:e,sqlName:i.sqlName,length:i.length};return}this.definition={...e};}with(e){return new n({...this.definition,...e})}sql(e){return this.with({sqlName:e})}notNull(){return this.with({notNull:true,nullable:false})}nullable(){return this.with({nullable:true,notNull:false})}primaryKey(e={}){return this.with({primaryKey:true,autoIncrement:e.autoIncrement??this.definition.autoIncrement})}unique(e){return this.with({unique:e?{name:e}:true})}index(e){return this.with({index:e?{name:e}:true})}default(e){return this.with({sqlDefault:e})}defaultFn(e){return this.with({runtimeDefaultFn:e})}defaultNow(){return this.with({nowDefault:true,runtimeDefaultFn:()=>new Date})}references(e,i="id",o={}){return this.with({references:{table:e,column:i,onDelete:o.onDelete,onUpdate:o.onUpdate}})}toDefinition(){return {...this.definition}}};function a(n,e={}){let i={},o={};for(let[t,r]of Object.entries(n)){if(r instanceof l){i[t]=r.toDefinition();continue}if(r.kind==="relation"){o[t]=r;continue}throw new Error(`Invalid table field '${t}'. Use column builders or relation helpers.`)}return {kind:"table",sqlName:e.sqlName,columns:i,relations:o}}function u(n){return {kind:"schema",tables:n}}function s(n){if(typeof n!="object"||n===null)return false;let e=n;return e.kind==="schema"&&typeof e.tables=="object"}function p(n,e,i={}){let o=typeof e=="string"?e:void 0,t=typeof e=="string"?i:e??i;return {kind:"relation",relation:"one",targetTable:n,field:t.field??o,referenceField:t.referenceField,fkType:t.fkType,sqlName:t.sqlName,notNull:t.notNull,nullable:t.nullable,onDelete:t.onDelete,onUpdate:t.onUpdate}}function f(n,e,i={}){let o=typeof e=="string"?e:void 0,t=typeof e=="string"?i:e??i;return {kind:"relation",relation:"many",targetTable:n,field:t.field??o,referenceField:t.referenceField,fkType:t.fkType,sqlName:t.sqlName,notNull:t.notNull,nullable:t.nullable,onDelete:t.onDelete,onUpdate:t.onUpdate}}var m={int:(n={})=>new l("int",n),number:(n={})=>new l("int",n),string:(n={})=>new l("string",n),boolean:(n={})=>new l("boolean",n),date:(n={})=>new l("date",n),uuid:(n={})=>new l({kind:"column",type:"string",sqlName:n.sqlName,length:n.length??36,primaryKey:true,notNull:true,nullable:false,uuidPrimaryKey:true,runtimeDefaultFn:()=>crypto.randomUUID()}),one:(n,e,i={})=>p(n,e,i),many:(n,e,i={})=>f(n,e,i)};exports.isSchemaDefinition=s;exports.schema=u;exports.table=a;exports.v=m;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var l=class n{definition;constructor(e,i={}){if(typeof e=="string"){this.definition={kind:"column",type:e,sqlName:i.sqlName,length:i.length};return}this.definition={...e};}with(e){return new n({...this.definition,...e})}sql(e){return this.with({sqlName:e})}notNull(){return this.with({notNull:true,nullable:false})}nullable(){return this.with({nullable:true,notNull:false})}primaryKey(e={}){return this.with({primaryKey:true,autoIncrement:e.autoIncrement??this.definition.autoIncrement})}unique(e){return this.with({unique:e?{name:e}:true})}index(e){return this.with({index:e?{name:e}:true})}default(e){return this.with({sqlDefault:e})}defaultFn(e){return this.with({runtimeDefaultFn:e})}defaultNow(){return this.with({nowDefault:true,runtimeDefaultFn:()=>new Date})}references(e,i="id",o={}){return this.with({references:{table:e,column:i,onDelete:o.onDelete,onUpdate:o.onUpdate}})}toDefinition(){return {...this.definition}}};function a(n,e={}){let i={},o={};for(let[t,r]of Object.entries(n)){if(r instanceof l){i[t]=r.toDefinition();continue}if(r.kind==="relation"){o[t]=r;continue}throw new Error(`Invalid table field '${t}'. Use column builders or relation helpers.`)}return {kind:"table",sqlName:e.sqlName,columns:i,relations:o}}function u(n){return {kind:"schema",tables:n}}function s(n){if(typeof n!="object"||n===null)return false;let e=n;return e.kind==="schema"&&typeof e.tables=="object"}function p(n,e,i={}){let o=typeof e=="string"?e:void 0,t=typeof e=="string"?i:e??i;return {kind:"relation",relation:"one",targetTable:n,field:t.field??o,referenceField:t.referenceField,fkType:t.fkType,sqlName:t.sqlName,notNull:t.notNull,nullable:t.nullable,onDelete:t.onDelete,onUpdate:t.onUpdate}}function f(n,e,i={}){let o=typeof e=="string"?e:void 0,t=typeof e=="string"?i:e??i;return {kind:"relation",relation:"many",targetTable:n,field:t.field??o,referenceField:t.referenceField,fkType:t.fkType,sqlName:t.sqlName,notNull:t.notNull,nullable:t.nullable,onDelete:t.onDelete,onUpdate:t.onUpdate}}var m={int:(n={})=>new l("int",n),number:(n={})=>new l("int",n),string:(n={})=>new l("string",n),boolean:(n={})=>new l("boolean",n),date:(n={})=>new l("date",n),uuid:(n={})=>new l({kind:"column",type:"string",sqlName:n.sqlName,length:n.length??36,primaryKey:true,notNull:true,nullable:false,uuidPrimaryKey:true,runtimeDefaultFn:()=>crypto.randomUUID()}),one:(n,e,i={})=>p(n,e,i),many:(n,e,i={})=>f(n,e,i)};export{s as isSchemaDefinition,u as schema,a as table,m as v};
|
package/package.json
CHANGED
package/schema.ts
CHANGED
|
@@ -41,6 +41,8 @@ export type RelationManyOptions = {
|
|
|
41
41
|
export type ColumnReference = {
|
|
42
42
|
table: string;
|
|
43
43
|
column: string;
|
|
44
|
+
onDelete?: ForeignKeyAction;
|
|
45
|
+
onUpdate?: ForeignKeyAction;
|
|
44
46
|
};
|
|
45
47
|
|
|
46
48
|
export type ColumnDefinition = {
|
|
@@ -187,8 +189,19 @@ export class ColumnBuilder {
|
|
|
187
189
|
});
|
|
188
190
|
}
|
|
189
191
|
|
|
190
|
-
public references(
|
|
191
|
-
|
|
192
|
+
public references(
|
|
193
|
+
table: string,
|
|
194
|
+
column = "id",
|
|
195
|
+
actions: Pick<ColumnReference, "onDelete" | "onUpdate"> = {},
|
|
196
|
+
): ColumnBuilder {
|
|
197
|
+
return this.with({
|
|
198
|
+
references: {
|
|
199
|
+
table,
|
|
200
|
+
column,
|
|
201
|
+
onDelete: actions.onDelete,
|
|
202
|
+
onUpdate: actions.onUpdate,
|
|
203
|
+
},
|
|
204
|
+
});
|
|
192
205
|
}
|
|
193
206
|
|
|
194
207
|
public toDefinition(): ColumnDefinition {
|
|
@@ -303,6 +316,8 @@ function buildManyRelation(
|
|
|
303
316
|
export const v = {
|
|
304
317
|
int: (options: ColumnBuilderOptions = {}) =>
|
|
305
318
|
new ColumnBuilder("int", options),
|
|
319
|
+
number: (options: ColumnBuilderOptions = {}) =>
|
|
320
|
+
new ColumnBuilder("int", options),
|
|
306
321
|
string: (options: ColumnBuilderOptions = {}) =>
|
|
307
322
|
new ColumnBuilder("string", options),
|
|
308
323
|
boolean: (options: ColumnBuilderOptions = {}) =>
|
|
@@ -322,6 +337,8 @@ export const v = {
|
|
|
322
337
|
sqlName: options.sqlName,
|
|
323
338
|
length: options.length ?? 36,
|
|
324
339
|
primaryKey: true,
|
|
340
|
+
notNull: true,
|
|
341
|
+
nullable: false,
|
|
325
342
|
uuidPrimaryKey: true,
|
|
326
343
|
runtimeDefaultFn: () => crypto.randomUUID(),
|
|
327
344
|
}),
|