@primate/core 0.6.2 → 0.7.0

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.
Files changed (185) hide show
  1. package/lib/private/App.d.ts +76 -149
  2. package/lib/private/App.js +22 -6
  3. package/lib/private/Flags.d.ts +5 -3
  4. package/lib/private/Flags.js +4 -2
  5. package/lib/private/app/Facade.d.ts +77 -156
  6. package/lib/private/app/Facade.js +4 -1
  7. package/lib/private/build/App.d.ts +4 -2
  8. package/lib/private/build/App.js +13 -4
  9. package/lib/private/build/client/index.js +24 -10
  10. package/lib/private/build/client/plugin/routes.d.ts +4 -0
  11. package/lib/private/build/client/plugin/routes.js +74 -0
  12. package/lib/private/build/hook.js +14 -6
  13. package/lib/private/build/index.d.ts +3 -2
  14. package/lib/private/build/index.js +9 -15
  15. package/lib/private/build/preclient/index.d.ts +3 -0
  16. package/lib/private/build/preclient/index.js +69 -0
  17. package/lib/private/build/preclient/plugin/routes.d.ts +4 -0
  18. package/lib/private/build/preclient/plugin/routes.js +44 -0
  19. package/lib/private/build/server/index.js +8 -5
  20. package/lib/private/build/server/plugin/assets.js +3 -3
  21. package/lib/private/build/server/plugin/native-addons.js +6 -8
  22. package/lib/private/build/server/plugin/node-imports.js +5 -7
  23. package/lib/private/build/server/plugin/route-client.d.ts +4 -0
  24. package/lib/private/build/server/plugin/route-client.js +110 -0
  25. package/lib/private/build/server/plugin/route.js +3 -10
  26. package/lib/private/build/server/plugin/virtual-pages.js +3 -3
  27. package/lib/private/build/server/plugin/virtual-routes.d.ts +2 -1
  28. package/lib/private/build/server/plugin/virtual-routes.js +27 -8
  29. package/lib/private/build/server/plugin/wasm.js +3 -2
  30. package/lib/private/client/Data.d.ts +1 -1
  31. package/lib/private/client/boot.js +2 -2
  32. package/lib/private/client/create-form.d.ts +11 -1
  33. package/lib/private/client/create-form.js +21 -3
  34. package/lib/private/client/index.d.ts +2 -2
  35. package/lib/private/client/navigate.d.ts +1 -0
  36. package/lib/private/client/navigate.js +7 -6
  37. package/lib/private/client/submit.d.ts +2 -1
  38. package/lib/private/client/submit.js +8 -7
  39. package/lib/private/client/{http.d.ts → transport.d.ts} +3 -3
  40. package/lib/private/client/{http.js → transport.js} +7 -9
  41. package/lib/private/config/schema.d.ts +5 -13
  42. package/lib/private/config/schema.js +1 -5
  43. package/lib/private/db/DB.d.ts +3 -1
  44. package/lib/private/db/MemoryDB.d.ts +5 -2
  45. package/lib/private/db/MemoryDB.js +33 -19
  46. package/lib/private/db/SQLDB.d.ts +23 -0
  47. package/lib/private/db/SQLDB.js +2 -0
  48. package/lib/private/db/errors.d.ts +74 -7
  49. package/lib/private/db/errors.js +31 -7
  50. package/lib/private/db/migrate/apply.js +8 -9
  51. package/lib/private/db/migrate/bundle.js +3 -2
  52. package/lib/private/db/migrate/create.js +18 -20
  53. package/lib/private/db/migrate/status.js +9 -10
  54. package/lib/private/db/migrate/store.d.ts +3 -3
  55. package/lib/private/db/migrate/store.js +5 -5
  56. package/lib/private/db/test.js +256 -115
  57. package/lib/private/db/testSQL.d.ts +50 -0
  58. package/lib/private/db/testSQL.js +196 -0
  59. package/lib/private/errors.d.ts +66 -9
  60. package/lib/private/errors.js +37 -16
  61. package/lib/private/frontend.d.ts +4 -4
  62. package/lib/private/frontend.js +11 -8
  63. package/lib/private/i18n/errors.d.ts +7 -1
  64. package/lib/private/i18n/errors.js +1 -1
  65. package/lib/private/i18n/index/types.d.ts +1 -1
  66. package/lib/private/i18n/locale.d.ts +1 -1
  67. package/lib/private/i18n/module.js +6 -5
  68. package/lib/private/index.d.ts +10 -2
  69. package/lib/private/index.js +13 -1
  70. package/lib/private/logger.d.ts +24 -0
  71. package/lib/private/logger.js +66 -0
  72. package/lib/private/module/Setup.d.ts +3 -0
  73. package/lib/private/module/create.d.ts +2 -1
  74. package/lib/private/module/create.js +4 -0
  75. package/lib/private/paths.d.ts +2 -3
  76. package/lib/private/paths.js +6 -12
  77. package/lib/private/request/ContentType.d.ts +3 -0
  78. package/lib/private/request/ContentType.js +2 -0
  79. package/lib/private/request/RequestBag.d.ts +2 -18
  80. package/lib/private/request/RequestBag.js +4 -16
  81. package/lib/private/request/RequestBody.d.ts +20 -28
  82. package/lib/private/request/RequestBody.js +63 -86
  83. package/lib/private/request/RequestFacade.d.ts +2 -2
  84. package/lib/private/request/handle.js +2 -2
  85. package/lib/private/request/parse.js +2 -4
  86. package/lib/private/request/route.js +15 -8
  87. package/lib/private/response/binary.d.ts +2 -2
  88. package/lib/private/response/binary.js +6 -6
  89. package/lib/private/response/error.js +6 -2
  90. package/lib/private/response/json.js +2 -2
  91. package/lib/private/response/null.d.ts +3 -0
  92. package/lib/private/response/null.js +6 -0
  93. package/lib/private/response/redirect.js +4 -3
  94. package/lib/private/response/respond.js +4 -4
  95. package/lib/private/response/sse.js +2 -2
  96. package/lib/private/response/text.js +2 -2
  97. package/lib/private/route/ContentTypeMap.d.ts +10 -0
  98. package/lib/private/route/ContentTypeMap.js +2 -0
  99. package/lib/private/route/Handler.d.ts +3 -2
  100. package/lib/private/route/NarrowedRequest.d.ts +23 -0
  101. package/lib/private/route/NarrowedRequest.js +2 -0
  102. package/lib/private/route/Options.d.ts +6 -1
  103. package/lib/private/route/Path.d.ts +2 -2
  104. package/lib/private/route/hook.d.ts +3 -1
  105. package/lib/private/route/hook.js +1 -2
  106. package/lib/private/route/router.d.ts +7 -11
  107. package/lib/private/route/router.js +13 -20
  108. package/lib/private/route.client.d.ts +36 -0
  109. package/lib/private/route.client.js +8 -0
  110. package/lib/private/route.d.ts +21 -5
  111. package/lib/private/route.js +21 -5
  112. package/lib/private/serve/App.d.ts +1 -2
  113. package/lib/private/serve/App.js +64 -58
  114. package/lib/private/serve/Init.d.ts +2 -0
  115. package/lib/private/serve/dev-module.js +2 -3
  116. package/lib/private/serve/index.js +5 -6
  117. package/lib/private/server/TAG.d.ts +1 -1
  118. package/lib/private/server/TAG.js +1 -1
  119. package/lib/private/session/index.d.ts +1 -1
  120. package/lib/private/session/index.js +3 -2
  121. package/lib/private/session/module.js +3 -3
  122. package/lib/private/session/schema.d.ts +3 -3
  123. package/lib/private/session/schema.js +4 -3
  124. package/lib/private/store/ExtractRelation.d.ts +7 -0
  125. package/lib/private/store/ExtractRelation.js +2 -0
  126. package/lib/private/store/ExtractSchema.d.ts +10 -0
  127. package/lib/private/{orm → store}/ForeignKey.d.ts +1 -1
  128. package/lib/private/store/Init.d.ts +13 -0
  129. package/lib/private/store/Init.js +2 -0
  130. package/lib/private/{orm/store.d.ts → store/Store.d.ts} +50 -50
  131. package/lib/private/{orm/store.js → store/Store.js} +163 -107
  132. package/lib/private/store/StoreInput.d.ts +11 -0
  133. package/lib/private/store/key.d.ts +8 -0
  134. package/lib/private/store/key.js +8 -0
  135. package/lib/private/{orm → store}/parse.d.ts +3 -3
  136. package/lib/private/{orm → store}/parse.js +7 -2
  137. package/lib/private/store/relation.d.ts +29 -0
  138. package/lib/private/store/relation.js +26 -0
  139. package/lib/private/store.d.ts +24 -0
  140. package/lib/private/store.js +10 -0
  141. package/lib/public/db/errors.d.ts +1 -1
  142. package/lib/public/db/errors.js +1 -1
  143. package/lib/public/db/testSQL.d.ts +2 -0
  144. package/lib/public/db/testSQL.js +2 -0
  145. package/lib/public/db.d.ts +1 -0
  146. package/lib/public/index.d.ts +1 -0
  147. package/lib/public/index.js +1 -1
  148. package/lib/public/response.d.ts +6 -6
  149. package/lib/public/response.js +4 -1
  150. package/lib/public/route.client.d.ts +2 -0
  151. package/lib/public/route.client.js +2 -0
  152. package/lib/public/store.d.ts +2 -0
  153. package/lib/public/store.js +2 -0
  154. package/package.json +24 -17
  155. package/lib/private/bye.d.ts +0 -3
  156. package/lib/private/bye.js +0 -4
  157. package/lib/private/log.d.ts +0 -20
  158. package/lib/private/log.js +0 -47
  159. package/lib/private/orm/ExtractSchema.d.ts +0 -9
  160. package/lib/private/orm/StoreInput.d.ts +0 -10
  161. package/lib/private/orm/key.d.ts +0 -8
  162. package/lib/private/orm/key.js +0 -8
  163. package/lib/private/orm/relation.d.ts +0 -43
  164. package/lib/private/orm/relation.js +0 -26
  165. package/lib/private/request/Verb.d.ts +0 -4
  166. package/lib/private/request/Verb.js +0 -2
  167. package/lib/private/request/verbs.d.ts +0 -3
  168. package/lib/private/request/verbs.js +0 -12
  169. package/lib/private/route/wrap.d.ts +0 -2
  170. package/lib/private/route/wrap.js +0 -12
  171. package/lib/public/log.d.ts +0 -2
  172. package/lib/public/log.js +0 -2
  173. package/lib/public/orm/key.d.ts +0 -2
  174. package/lib/public/orm/key.js +0 -2
  175. package/lib/public/orm/relation.d.ts +0 -2
  176. package/lib/public/orm/relation.js +0 -2
  177. package/lib/public/orm/store.d.ts +0 -2
  178. package/lib/public/orm/store.js +0 -2
  179. package/lib/public/request/verbs.d.ts +0 -2
  180. package/lib/public/request/verbs.js +0 -2
  181. /package/lib/private/{orm → store}/ExtractSchema.js +0 -0
  182. /package/lib/private/{orm → store}/ForeignKey.js +0 -0
  183. /package/lib/private/{orm → store}/PrimaryKey.d.ts +0 -0
  184. /package/lib/private/{orm → store}/PrimaryKey.js +0 -0
  185. /package/lib/private/{orm → store}/StoreInput.js +0 -0
@@ -1,13 +1,17 @@
1
+ import type DataDict from "#db/DataDict";
1
2
  import type DB from "#db/DB";
2
3
  import type PK from "#db/PK";
3
4
  import type Types from "#db/Types";
4
- import type ExtractSchema from "#orm/ExtractSchema";
5
- import type PrimaryKey from "#orm/PrimaryKey";
6
- import type { ManyRelation, OneRelation, Relation } from "#orm/relation";
7
- import type StoreInput from "#orm/StoreInput";
8
- import type { Dict, EmptyObject, Serializable } from "@rcompat/type";
5
+ import type ExtractRelations from "#store/ExtractRelation";
6
+ import type ExtractSchema from "#store/ExtractSchema";
7
+ import type Init from "#store/Init";
8
+ import type PrimaryKey from "#store/PrimaryKey";
9
+ import type { ManyRelation, OneRelation, Relation } from "#store/relation";
10
+ import type StoreInput from "#store/StoreInput";
11
+ import type { Dict, Serializable } from "@rcompat/type";
9
12
  import type { DefaultType, InferStore, Storable } from "pema";
10
13
  import StoreType from "pema/StoreType";
14
+ declare const brand: unique symbol;
11
15
  type X<T> = {
12
16
  [K in keyof T]: T[K];
13
17
  } & {};
@@ -17,6 +21,7 @@ type OrNull<T> = {
17
21
  type StringOperators = {
18
22
  $like?: string;
19
23
  $ilike?: string;
24
+ $in?: string[];
20
25
  };
21
26
  type NumberOperators = {
22
27
  $gt?: number;
@@ -24,6 +29,7 @@ type NumberOperators = {
24
29
  $lt?: number;
25
30
  $lte?: number;
26
31
  $ne?: number;
32
+ $in?: number[];
27
33
  };
28
34
  type BigIntOperators = {
29
35
  $gt?: bigint;
@@ -31,11 +37,13 @@ type BigIntOperators = {
31
37
  $lt?: bigint;
32
38
  $lte?: bigint;
33
39
  $ne?: bigint;
40
+ $in?: bigint[];
34
41
  };
35
42
  type DateOperators = {
36
43
  $before?: Date;
37
44
  $after?: Date;
38
45
  $ne?: Date;
46
+ $in?: Date[];
39
47
  };
40
48
  type QueryOperators<T> = T extends string ? (T | StringOperators | null) : T extends number ? (T | NumberOperators | null) : T extends bigint ? (T | BigIntOperators | null) : T extends Date ? (T | DateOperators | null) : (T | null);
41
49
  type InferRecord<T extends StoreInput> = InferStore<ExtractSchema<T>>;
@@ -55,37 +63,30 @@ type Insertable<T extends StoreInput> = Omit<InferRecord<T>, PrimaryKeyField<T>
55
63
  type PrimaryKeyField<T extends StoreInput> = {
56
64
  [K in keyof T]: T[K] extends PrimaryKey<any> ? K : never;
57
65
  }[keyof T] & keyof InferRecord<T>;
66
+ type SchemaOf<S> = S extends Store<infer T, any> ? Schema<T> : never;
67
+ type StoreT<S> = S extends Store<infer T, any> ? T : never;
68
+ type RelationTable<R> = R extends OneRelation<infer N, string> ? N : R extends ManyRelation<infer N, string> ? N : never;
69
+ type RelationStore<N extends string> = Store<any, N>;
70
+ type WithQuery<N extends string, S extends RelationStore<N> = RelationStore<N>> = {
71
+ store: S;
72
+ where?: Where<StoreT<S>> & DataDict;
73
+ select?: readonly (keyof Schema<StoreT<S>> & string)[];
74
+ sort?: Sort<Schema<StoreT<S>>> & ReadSort;
75
+ limit?: number;
76
+ };
77
+ type WithInput<R extends Dict<Relation>> = {
78
+ [K in keyof R]?: RelationStore<RelationTable<R[K]>> | WithQuery<RelationTable<R[K]>, RelationStore<RelationTable<R[K]>>>;
79
+ };
80
+ type RelationResult<Rel, W> = Rel extends OneRelation<string, string> ? W extends WithQuery<string, infer S> ? W["select"] extends readonly (keyof SchemaOf<S> & string)[] ? Pick<SchemaOf<S>, W["select"][number]> | null : SchemaOf<S> | null : SchemaOf<W> | null : Rel extends ManyRelation<string, string> ? W extends WithQuery<string, infer S> ? W["select"] extends readonly (keyof SchemaOf<S> & string)[] ? Pick<SchemaOf<S>, W["select"][number]>[] : SchemaOf<S>[] : SchemaOf<W>[] : never;
81
+ type WithRelations<Base, R extends Dict<Relation>, W extends WithInput<R> | undefined> = W extends object ? X<Base & {
82
+ [K in keyof W & keyof R]: RelationResult<R[K], W[K]>;
83
+ }> : Base;
58
84
  declare const NUMBER_KEYS: readonly ["u8", "u16", "u32", "i8", "i16", "i32", "f32", "f64"];
59
85
  declare const BIGINT_KEYS: readonly ["u64", "u128", "i64", "i128"];
60
86
  type NumberKey = typeof NUMBER_KEYS[number];
61
87
  type BigIntKey = typeof BIGINT_KEYS[number];
62
88
  type PKV<T extends StoreInput> = T[PrimaryKeyField<T>] extends PrimaryKey<infer P> ? P extends Storable<infer D> ? D extends "uuid" | "uuid_v4" | "uuid_v7" ? string : D extends NumberKey ? number : D extends BigIntKey ? bigint : string | number | bigint : string | number | bigint : string | number | bigint;
63
- type WithQuery<T extends StoreInput> = true | {
64
- where?: Where<T>;
65
- select?: Select<Schema<T>>;
66
- sort?: Sort<Schema<T>>;
67
- limit?: number;
68
- };
69
- type With<R extends Dict<Relation>> = {
70
- [K in keyof R]?: R[K] extends OneRelation<infer S, string> ? WithQuery<S> : R[K] extends ManyRelation<infer S, string> ? WithQuery<S> : never;
71
- };
72
- type RelationResult<Rel, Q> = Rel extends OneRelation<infer S, string> ? Q extends {
73
- select: infer Sel;
74
- } ? Sel extends Select<Schema<S>> ? Projected<Schema<S>, Sel> | null : Schema<S> | null : Schema<S> | null : Rel extends ManyRelation<infer S, string> ? Q extends {
75
- select: infer Sel;
76
- } ? Sel extends Select<Schema<S>> ? Projected<Schema<S>, Sel>[] : Schema<S>[] : Schema<S>[] : never;
77
- type WithRelations<Base, Relations extends Dict<Relation>, W extends With<Relations> | undefined> = W extends object ? X<Base & {
78
- [K in keyof W & keyof Relations]: RelationResult<Relations[K], W[K]>;
79
- }> : Base;
80
- type Init<S extends StoreInput, R extends Dict<Relation>> = {
81
- name: string;
82
- db: DB;
83
- id?: symbol;
84
- schema: S;
85
- relations?: R;
86
- migrate?: boolean;
87
- extend?: Dict;
88
- };
89
+ type ReadSort = Dict<"asc" | "desc">;
89
90
  /**
90
91
  * Database-backed store.
91
92
  *
@@ -93,22 +94,21 @@ type Init<S extends StoreInput, R extends Dict<Relation>> = {
93
94
  * document database table/collection. It pairs a Pema schema with a uniform
94
95
  * CRUD/query API.
95
96
  */
96
- export declare class Store<T extends StoreInput, R extends Dict<Relation> = EmptyObject> implements Serializable {
97
+ export default class Store<T extends StoreInput, N extends string = string> implements Serializable {
97
98
  #private;
99
+ [brand]: boolean;
98
100
  readonly Schema: Schema<T>;
99
- constructor(init: Init<T, R>);
100
- get table(): {
101
- create: () => import("@rcompat/type").MaybePromise<void>;
102
- delete: () => import("@rcompat/type").MaybePromise<void>;
103
- };
101
+ static is(x: unknown): x is Store<any, any>;
102
+ constructor(init: Init<T, N>);
103
+ create(): Promise<void>;
104
+ drop(): Promise<void>;
104
105
  get infer(): InferRecord<T>;
105
- get schema(): Dict<Storable<keyof import("pema").DataType, unknown>>;
106
- get type(): StoreType<ExtractSchema<T>>;
106
+ get schema(): StoreType<ExtractSchema<T>>;
107
107
  get migrate(): boolean;
108
108
  get id(): symbol;
109
- get name(): string;
109
+ get table(): N;
110
110
  get pk(): PK;
111
- get db(): DB;
111
+ get db(): DB<unknown>;
112
112
  get types(): Types;
113
113
  /**
114
114
  * Count records
@@ -128,18 +128,18 @@ export declare class Store<T extends StoreInput, R extends Dict<Relation> = Empt
128
128
  * - With `with`: augments the record with relations.
129
129
  */
130
130
  get(pkv: PKV<T>): Promise<Schema<T>>;
131
- get<const S extends Select<Schema<T>> | undefined = undefined, const W extends With<R> | undefined = undefined>(pkv: PKV<T>, options: {
131
+ get<const S extends Select<Schema<T>> | undefined = undefined, const W extends WithInput<ExtractRelations<T>> | undefined = undefined>(pkv: PKV<T>, options: {
132
132
  select?: S;
133
133
  with?: W;
134
- }): Promise<WithRelations<Projected<Schema<T>, S>, R, W>>;
134
+ }): Promise<WithRelations<Projected<Schema<T>, S>, ExtractRelations<T>, W>>;
135
135
  /**
136
136
  * Try to get a record by primary key.
137
137
  */
138
138
  try(pkv: PKV<T>): Promise<Schema<T> | undefined>;
139
- try<const S extends Select<Schema<T>> | undefined = undefined, const W extends With<R> | undefined = undefined>(pkv: PKV<T>, options: {
139
+ try<const S extends Select<Schema<T>> | undefined = undefined, const W extends WithInput<ExtractRelations<T>> | undefined = undefined>(pkv: PKV<T>, options: {
140
140
  select?: S;
141
141
  with?: W;
142
- }): Promise<WithRelations<Projected<Schema<T>, S>, R, W> | undefined>;
142
+ }): Promise<WithRelations<Projected<Schema<T>, S>, ExtractRelations<T>, W> | undefined>;
143
143
  /**
144
144
  * Insert a single record.
145
145
  */
@@ -171,19 +171,19 @@ export declare class Store<T extends StoreInput, R extends Dict<Relation> = Empt
171
171
  * Find matching records
172
172
  *
173
173
  */
174
- find<const S extends Select<Schema<T>> | undefined = undefined, const W extends With<R> | undefined = undefined>(options?: {
174
+ find<const S extends Select<Schema<T>> | undefined = undefined, const W extends WithInput<ExtractRelations<T>> | undefined = undefined>(options?: {
175
175
  where?: Where<T>;
176
176
  select?: S;
177
177
  sort?: Sort<Schema<T>>;
178
178
  limit?: number;
179
+ offset?: number;
179
180
  with?: W;
180
- }): Promise<WithRelations<Projected<Schema<T>, S>, R, W>[]>;
181
+ }): Promise<WithRelations<Projected<Schema<T>, S>, ExtractRelations<T>, W>[]>;
181
182
  toJSON(): {
182
183
  type: "object";
183
184
  properties: Dict<import("pema").Serialized>;
184
185
  };
185
186
  extend<A extends Dict>(extensor: (This: this) => A): this & A;
186
187
  }
187
- declare function store<T extends StoreInput, R extends Dict<Relation> = EmptyObject>(init: Init<T, R>): Store<T, R>;
188
- export default store;
189
- //# sourceMappingURL=store.d.ts.map
188
+ export {};
189
+ //# sourceMappingURL=Store.d.ts.map