@primate/core 0.6.3 → 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.
- package/lib/private/App.d.ts +76 -149
- package/lib/private/App.js +22 -6
- package/lib/private/Flags.d.ts +5 -3
- package/lib/private/Flags.js +4 -2
- package/lib/private/app/Facade.d.ts +77 -156
- package/lib/private/app/Facade.js +4 -1
- package/lib/private/build/App.d.ts +4 -2
- package/lib/private/build/App.js +13 -4
- package/lib/private/build/client/index.js +24 -10
- package/lib/private/build/client/plugin/routes.d.ts +4 -0
- package/lib/private/build/client/plugin/routes.js +74 -0
- package/lib/private/build/hook.js +14 -6
- package/lib/private/build/index.d.ts +3 -2
- package/lib/private/build/index.js +9 -15
- package/lib/private/build/preclient/index.d.ts +3 -0
- package/lib/private/build/preclient/index.js +69 -0
- package/lib/private/build/preclient/plugin/routes.d.ts +4 -0
- package/lib/private/build/preclient/plugin/routes.js +44 -0
- package/lib/private/build/server/index.js +8 -5
- package/lib/private/build/server/plugin/assets.js +3 -3
- package/lib/private/build/server/plugin/native-addons.js +6 -8
- package/lib/private/build/server/plugin/node-imports.js +5 -7
- package/lib/private/build/server/plugin/route-client.d.ts +4 -0
- package/lib/private/build/server/plugin/route-client.js +110 -0
- package/lib/private/build/server/plugin/route.js +3 -10
- package/lib/private/build/server/plugin/virtual-pages.js +3 -3
- package/lib/private/build/server/plugin/virtual-routes.d.ts +2 -1
- package/lib/private/build/server/plugin/virtual-routes.js +27 -8
- package/lib/private/build/server/plugin/wasm.js +3 -2
- package/lib/private/client/Data.d.ts +1 -1
- package/lib/private/client/boot.js +2 -2
- package/lib/private/client/create-form.d.ts +11 -1
- package/lib/private/client/create-form.js +21 -3
- package/lib/private/client/index.d.ts +2 -2
- package/lib/private/client/navigate.d.ts +1 -0
- package/lib/private/client/navigate.js +7 -6
- package/lib/private/client/submit.d.ts +2 -1
- package/lib/private/client/submit.js +8 -7
- package/lib/private/client/{http.d.ts → transport.d.ts} +3 -3
- package/lib/private/client/{http.js → transport.js} +7 -9
- package/lib/private/config/schema.d.ts +5 -13
- package/lib/private/config/schema.js +1 -5
- package/lib/private/db/DB.d.ts +3 -1
- package/lib/private/db/MemoryDB.d.ts +5 -2
- package/lib/private/db/MemoryDB.js +33 -19
- package/lib/private/db/SQLDB.d.ts +23 -0
- package/lib/private/db/SQLDB.js +2 -0
- package/lib/private/db/errors.d.ts +74 -7
- package/lib/private/db/errors.js +31 -7
- package/lib/private/db/migrate/apply.js +8 -9
- package/lib/private/db/migrate/bundle.js +2 -2
- package/lib/private/db/migrate/create.js +18 -20
- package/lib/private/db/migrate/status.js +9 -10
- package/lib/private/db/migrate/store.d.ts +3 -3
- package/lib/private/db/migrate/store.js +5 -5
- package/lib/private/db/test.js +256 -115
- package/lib/private/db/testSQL.d.ts +50 -0
- package/lib/private/db/testSQL.js +196 -0
- package/lib/private/errors.d.ts +66 -9
- package/lib/private/errors.js +37 -16
- package/lib/private/frontend.d.ts +4 -4
- package/lib/private/frontend.js +11 -8
- package/lib/private/i18n/errors.d.ts +7 -1
- package/lib/private/i18n/errors.js +1 -1
- package/lib/private/i18n/index/types.d.ts +1 -1
- package/lib/private/i18n/locale.d.ts +1 -1
- package/lib/private/i18n/module.js +6 -5
- package/lib/private/index.d.ts +10 -2
- package/lib/private/index.js +13 -1
- package/lib/private/logger.d.ts +24 -0
- package/lib/private/logger.js +66 -0
- package/lib/private/module/Setup.d.ts +3 -0
- package/lib/private/module/create.d.ts +2 -1
- package/lib/private/module/create.js +4 -0
- package/lib/private/paths.d.ts +2 -3
- package/lib/private/paths.js +6 -12
- package/lib/private/request/ContentType.d.ts +3 -0
- package/lib/private/request/ContentType.js +2 -0
- package/lib/private/request/RequestBag.d.ts +2 -18
- package/lib/private/request/RequestBag.js +4 -16
- package/lib/private/request/RequestBody.d.ts +20 -28
- package/lib/private/request/RequestBody.js +63 -86
- package/lib/private/request/RequestFacade.d.ts +2 -2
- package/lib/private/request/handle.js +2 -2
- package/lib/private/request/parse.js +2 -4
- package/lib/private/request/route.js +15 -8
- package/lib/private/response/binary.d.ts +2 -2
- package/lib/private/response/binary.js +6 -6
- package/lib/private/response/error.js +6 -2
- package/lib/private/response/json.js +2 -2
- package/lib/private/response/null.d.ts +3 -0
- package/lib/private/response/null.js +6 -0
- package/lib/private/response/redirect.js +4 -3
- package/lib/private/response/respond.js +4 -4
- package/lib/private/response/sse.js +2 -2
- package/lib/private/response/text.js +2 -2
- package/lib/private/route/ContentTypeMap.d.ts +10 -0
- package/lib/private/route/ContentTypeMap.js +2 -0
- package/lib/private/route/Handler.d.ts +3 -2
- package/lib/private/route/NarrowedRequest.d.ts +23 -0
- package/lib/private/route/NarrowedRequest.js +2 -0
- package/lib/private/route/Options.d.ts +6 -1
- package/lib/private/route/Path.d.ts +2 -2
- package/lib/private/route/hook.d.ts +3 -1
- package/lib/private/route/hook.js +1 -2
- package/lib/private/route/router.d.ts +7 -11
- package/lib/private/route/router.js +13 -20
- package/lib/private/route.client.d.ts +36 -0
- package/lib/private/route.client.js +8 -0
- package/lib/private/route.d.ts +21 -5
- package/lib/private/route.js +21 -5
- package/lib/private/serve/App.d.ts +1 -2
- package/lib/private/serve/App.js +64 -58
- package/lib/private/serve/Init.d.ts +2 -0
- package/lib/private/serve/dev-module.js +2 -3
- package/lib/private/serve/index.js +5 -6
- package/lib/private/server/TAG.d.ts +1 -1
- package/lib/private/server/TAG.js +1 -1
- package/lib/private/session/index.d.ts +1 -1
- package/lib/private/session/index.js +3 -2
- package/lib/private/session/module.js +3 -3
- package/lib/private/session/schema.d.ts +3 -3
- package/lib/private/session/schema.js +4 -3
- package/lib/private/store/ExtractRelation.d.ts +7 -0
- package/lib/private/store/ExtractRelation.js +2 -0
- package/lib/private/store/ExtractSchema.d.ts +10 -0
- package/lib/private/{orm → store}/ForeignKey.d.ts +1 -1
- package/lib/private/store/Init.d.ts +13 -0
- package/lib/private/store/Init.js +2 -0
- package/lib/private/{orm/store.d.ts → store/Store.d.ts} +50 -50
- package/lib/private/{orm/store.js → store/Store.js} +163 -107
- package/lib/private/store/StoreInput.d.ts +11 -0
- package/lib/private/store/key.d.ts +8 -0
- package/lib/private/store/key.js +8 -0
- package/lib/private/{orm → store}/parse.d.ts +3 -3
- package/lib/private/{orm → store}/parse.js +7 -2
- package/lib/private/store/relation.d.ts +29 -0
- package/lib/private/store/relation.js +26 -0
- package/lib/private/store.d.ts +24 -0
- package/lib/private/store.js +10 -0
- package/lib/public/db/errors.d.ts +1 -1
- package/lib/public/db/errors.js +1 -1
- package/lib/public/db/testSQL.d.ts +2 -0
- package/lib/public/db/testSQL.js +2 -0
- package/lib/public/db.d.ts +1 -0
- package/lib/public/index.d.ts +1 -0
- package/lib/public/index.js +1 -1
- package/lib/public/response.d.ts +6 -6
- package/lib/public/response.js +4 -1
- package/lib/public/route.client.d.ts +2 -0
- package/lib/public/route.client.js +2 -0
- package/lib/public/store.d.ts +2 -0
- package/lib/public/store.js +2 -0
- package/package.json +24 -17
- package/lib/private/bye.d.ts +0 -3
- package/lib/private/bye.js +0 -4
- package/lib/private/log.d.ts +0 -20
- package/lib/private/log.js +0 -47
- package/lib/private/orm/ExtractSchema.d.ts +0 -9
- package/lib/private/orm/StoreInput.d.ts +0 -10
- package/lib/private/orm/key.d.ts +0 -8
- package/lib/private/orm/key.js +0 -8
- package/lib/private/orm/relation.d.ts +0 -43
- package/lib/private/orm/relation.js +0 -26
- package/lib/private/request/Verb.d.ts +0 -4
- package/lib/private/request/Verb.js +0 -2
- package/lib/private/request/verbs.d.ts +0 -3
- package/lib/private/request/verbs.js +0 -12
- package/lib/private/route/wrap.d.ts +0 -2
- package/lib/private/route/wrap.js +0 -12
- package/lib/public/log.d.ts +0 -2
- package/lib/public/log.js +0 -2
- package/lib/public/orm/key.d.ts +0 -2
- package/lib/public/orm/key.js +0 -2
- package/lib/public/orm/relation.d.ts +0 -2
- package/lib/public/orm/relation.js +0 -2
- package/lib/public/orm/store.d.ts +0 -2
- package/lib/public/orm/store.js +0 -2
- package/lib/public/request/verbs.d.ts +0 -2
- package/lib/public/request/verbs.js +0 -2
- /package/lib/private/{orm → store}/ExtractSchema.js +0 -0
- /package/lib/private/{orm → store}/ForeignKey.js +0 -0
- /package/lib/private/{orm → store}/PrimaryKey.d.ts +0 -0
- /package/lib/private/{orm → store}/PrimaryKey.js +0 -0
- /package/lib/private/{orm → store}/StoreInput.js +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
declare function db_missing(): import("@rcompat/error").TemplateError;
|
|
2
2
|
declare function store_directory_missing(): import("@rcompat/error").TemplateError;
|
|
3
3
|
declare function store_directory_empty(): import("@rcompat/error").TemplateError;
|
|
4
|
-
declare function
|
|
4
|
+
declare function store_table_required(): import("@rcompat/error").TemplateError;
|
|
5
5
|
declare function unregistered_schema(): import("@rcompat/error").TemplateError;
|
|
6
6
|
declare function record_not_found(field: string, value: string | number | bigint): import("@rcompat/error").TemplateError;
|
|
7
7
|
declare function key_duplicate(key: string): import("@rcompat/error").TemplateError;
|
|
@@ -23,10 +23,11 @@ declare function field_required(operator: string): import("@rcompat/error").Temp
|
|
|
23
23
|
declare function field_undefined(field: string, context: Context): import("@rcompat/error").TemplateError;
|
|
24
24
|
declare function fields_unknown(fields: string[]): import("@rcompat/error").TemplateError;
|
|
25
25
|
declare function null_not_allowed(field: string): import("@rcompat/error").TemplateError;
|
|
26
|
-
declare function wrong_type(type: "string" | "number" | "bigint" | "boolean" | "url" | "date" | "blob", field: string, got: unknown, op?: string): import("@rcompat/error").TemplateError;
|
|
26
|
+
declare function wrong_type(type: "string" | "number" | "bigint" | "boolean" | "url" | "date" | "blob" | "array", field: string, got: unknown, op?: string): import("@rcompat/error").TemplateError;
|
|
27
27
|
declare function operator_unknown(field: string, operator: string): import("@rcompat/error").TemplateError;
|
|
28
28
|
declare function operator_empty(field: string): import("@rcompat/error").TemplateError;
|
|
29
29
|
declare function operator_scalar(field: string): import("@rcompat/error").TemplateError;
|
|
30
|
+
declare function operator_empty_in(key: string): import("@rcompat/error").TemplateError;
|
|
30
31
|
declare function sort_empty(): import("@rcompat/error").TemplateError;
|
|
31
32
|
declare function sort_invalid(): import("@rcompat/error").TemplateError;
|
|
32
33
|
declare function sort_invalid_value(field: string, value: unknown): import("@rcompat/error").TemplateError;
|
|
@@ -38,9 +39,12 @@ declare function where_required(): import("@rcompat/error").TemplateError;
|
|
|
38
39
|
declare function where_invalid(): import("@rcompat/error").TemplateError;
|
|
39
40
|
declare function where_invalid_value(field: string, value: unknown): import("@rcompat/error").TemplateError;
|
|
40
41
|
declare function set_empty(): import("@rcompat/error").TemplateError;
|
|
41
|
-
declare function
|
|
42
|
+
declare function offset_invalid(): import("@rcompat/error").TemplateError;
|
|
43
|
+
declare function offset_requires_limit(): import("@rcompat/error").TemplateError;
|
|
44
|
+
declare function relation_unknown(relation: PropertyKey): import("@rcompat/error").TemplateError;
|
|
42
45
|
declare function relation_requires_pk(type: "target" | "parent"): import("@rcompat/error").TemplateError;
|
|
43
|
-
declare function
|
|
46
|
+
declare function relation_table_mismatch(expected: string, actual: string): import("@rcompat/error").TemplateError;
|
|
47
|
+
declare function relation_store_required(name: PropertyKey): import("@rcompat/error").TemplateError;
|
|
44
48
|
declare function option_unknown(option: string): import("@rcompat/error").TemplateError;
|
|
45
49
|
declare function identifier_invalid(identifier: string): import("@rcompat/error").TemplateError;
|
|
46
50
|
declare function count_with_invalid(): import("@rcompat/error").TemplateError;
|
|
@@ -48,6 +52,8 @@ declare function count_overflow(table: string, count: unknown): import("@rcompat
|
|
|
48
52
|
declare function migration_directory_missing(): import("@rcompat/error").TemplateError;
|
|
49
53
|
declare function migration_store_conflict(message: string): import("@rcompat/error").TemplateError;
|
|
50
54
|
declare function unapplied_migrations(): import("@rcompat/error").TemplateError;
|
|
55
|
+
declare function sql_placeholder_missing(key: string): import("@rcompat/error").TemplateError;
|
|
56
|
+
declare function sql_input_missing(key: string): import("@rcompat/error").TemplateError;
|
|
51
57
|
declare const errors: {
|
|
52
58
|
option_unknown: typeof option_unknown;
|
|
53
59
|
identifier_invalid: typeof identifier_invalid;
|
|
@@ -56,9 +62,12 @@ declare const errors: {
|
|
|
56
62
|
migration_directory_missing: typeof migration_directory_missing;
|
|
57
63
|
migration_store_conflict: typeof migration_store_conflict;
|
|
58
64
|
unapplied_migrations: typeof unapplied_migrations;
|
|
65
|
+
sql_placeholder_missing: typeof sql_placeholder_missing;
|
|
66
|
+
sql_input_missing: typeof sql_input_missing;
|
|
59
67
|
relation_unknown: typeof relation_unknown;
|
|
60
68
|
relation_requires_pk: typeof relation_requires_pk;
|
|
61
|
-
|
|
69
|
+
relation_table_mismatch: typeof relation_table_mismatch;
|
|
70
|
+
relation_store_required: typeof relation_store_required;
|
|
62
71
|
sort_empty: typeof sort_empty;
|
|
63
72
|
sort_invalid: typeof sort_invalid;
|
|
64
73
|
sort_invalid_value: typeof sort_invalid_value;
|
|
@@ -70,10 +79,13 @@ declare const errors: {
|
|
|
70
79
|
where_invalid_value: typeof where_invalid_value;
|
|
71
80
|
set_empty: typeof set_empty;
|
|
72
81
|
limit_invalid: typeof limit_invalid;
|
|
82
|
+
offset_invalid: typeof offset_invalid;
|
|
83
|
+
offset_requires_limit: typeof offset_requires_limit;
|
|
73
84
|
operator_unknown: typeof operator_unknown;
|
|
74
85
|
operator_empty: typeof operator_empty;
|
|
75
86
|
wrong_type: typeof wrong_type;
|
|
76
87
|
operator_scalar: typeof operator_scalar;
|
|
88
|
+
operator_empty_in: typeof operator_empty_in;
|
|
77
89
|
null_not_allowed: typeof null_not_allowed;
|
|
78
90
|
field_unknown: typeof field_unknown;
|
|
79
91
|
field_duplicate: typeof field_duplicate;
|
|
@@ -90,7 +102,7 @@ declare const errors: {
|
|
|
90
102
|
db_missing: typeof db_missing;
|
|
91
103
|
store_directory_missing: typeof store_directory_missing;
|
|
92
104
|
store_directory_empty: typeof store_directory_empty;
|
|
93
|
-
|
|
105
|
+
store_table_required: typeof store_table_required;
|
|
94
106
|
unregistered_schema: typeof unregistered_schema;
|
|
95
107
|
record_not_found: typeof record_not_found;
|
|
96
108
|
record_number_invalid: typeof record_number_invalid;
|
|
@@ -98,7 +110,62 @@ declare const errors: {
|
|
|
98
110
|
key_duplicate: typeof key_duplicate;
|
|
99
111
|
table_not_found: typeof table_not_found;
|
|
100
112
|
};
|
|
113
|
+
export declare const Code: {
|
|
114
|
+
option_unknown: "option_unknown";
|
|
115
|
+
identifier_invalid: "identifier_invalid";
|
|
116
|
+
count_with_invalid: "count_with_invalid";
|
|
117
|
+
count_overflow: "count_overflow";
|
|
118
|
+
migration_directory_missing: "migration_directory_missing";
|
|
119
|
+
migration_store_conflict: "migration_store_conflict";
|
|
120
|
+
unapplied_migrations: "unapplied_migrations";
|
|
121
|
+
sql_placeholder_missing: "sql_placeholder_missing";
|
|
122
|
+
sql_input_missing: "sql_input_missing";
|
|
123
|
+
relation_unknown: "relation_unknown";
|
|
124
|
+
relation_requires_pk: "relation_requires_pk";
|
|
125
|
+
relation_table_mismatch: "relation_table_mismatch";
|
|
126
|
+
relation_store_required: "relation_store_required";
|
|
127
|
+
sort_empty: "sort_empty";
|
|
128
|
+
sort_invalid: "sort_invalid";
|
|
129
|
+
sort_invalid_value: "sort_invalid_value";
|
|
130
|
+
select_empty: "select_empty";
|
|
131
|
+
select_invalid: "select_invalid";
|
|
132
|
+
select_invalid_value: "select_invalid_value";
|
|
133
|
+
where_required: "where_required";
|
|
134
|
+
where_invalid: "where_invalid";
|
|
135
|
+
where_invalid_value: "where_invalid_value";
|
|
136
|
+
set_empty: "set_empty";
|
|
137
|
+
limit_invalid: "limit_invalid";
|
|
138
|
+
offset_invalid: "offset_invalid";
|
|
139
|
+
offset_requires_limit: "offset_requires_limit";
|
|
140
|
+
operator_unknown: "operator_unknown";
|
|
141
|
+
operator_empty: "operator_empty";
|
|
142
|
+
wrong_type: "wrong_type";
|
|
143
|
+
operator_scalar: "operator_scalar";
|
|
144
|
+
operator_empty_in: "operator_empty_in";
|
|
145
|
+
null_not_allowed: "null_not_allowed";
|
|
146
|
+
field_unknown: "field_unknown";
|
|
147
|
+
field_duplicate: "field_duplicate";
|
|
148
|
+
field_required: "field_required";
|
|
149
|
+
field_undefined: "field_undefined";
|
|
150
|
+
fields_unknown: "fields_unknown";
|
|
151
|
+
pk_undefined: "pk_undefined";
|
|
152
|
+
pk_immutable: "pk_immutable";
|
|
153
|
+
pk_duplicate: "pk_duplicate";
|
|
154
|
+
pk_invalid: "pk_invalid";
|
|
155
|
+
pk_required: "pk_required";
|
|
156
|
+
pk_multiple_pks: "pk_multiple_pks";
|
|
157
|
+
pk_invalid_type: "pk_invalid_type";
|
|
158
|
+
db_missing: "db_missing";
|
|
159
|
+
store_directory_missing: "store_directory_missing";
|
|
160
|
+
store_directory_empty: "store_directory_empty";
|
|
161
|
+
store_table_required: "store_table_required";
|
|
162
|
+
unregistered_schema: "unregistered_schema";
|
|
163
|
+
record_not_found: "record_not_found";
|
|
164
|
+
record_number_invalid: "record_number_invalid";
|
|
165
|
+
return_invalid: "return_invalid";
|
|
166
|
+
key_duplicate: "key_duplicate";
|
|
167
|
+
table_not_found: "table_not_found";
|
|
168
|
+
};
|
|
101
169
|
export type Code = keyof typeof errors;
|
|
102
|
-
export declare const Code: { [K in Code]: K; };
|
|
103
170
|
export default errors;
|
|
104
171
|
//# sourceMappingURL=errors.d.ts.map
|
package/lib/private/db/errors.js
CHANGED
|
@@ -21,8 +21,8 @@ function store_directory_missing() {
|
|
|
21
21
|
function store_directory_empty() {
|
|
22
22
|
return t `store directory empty`;
|
|
23
23
|
}
|
|
24
|
-
function
|
|
25
|
-
return t `store
|
|
24
|
+
function store_table_required() {
|
|
25
|
+
return t `store ${"table"} required`;
|
|
26
26
|
}
|
|
27
27
|
function unregistered_schema() {
|
|
28
28
|
return t `no store registered for schema`;
|
|
@@ -46,7 +46,7 @@ const STORE = error.coded({
|
|
|
46
46
|
db_missing,
|
|
47
47
|
store_directory_missing,
|
|
48
48
|
store_directory_empty,
|
|
49
|
-
|
|
49
|
+
store_table_required,
|
|
50
50
|
unregistered_schema,
|
|
51
51
|
record_not_found,
|
|
52
52
|
record_number_invalid,
|
|
@@ -124,11 +124,15 @@ function operator_empty(field) {
|
|
|
124
124
|
function operator_scalar(field) {
|
|
125
125
|
return t `${field}: operator requires scalar value`;
|
|
126
126
|
}
|
|
127
|
+
function operator_empty_in(key) {
|
|
128
|
+
return t `$in operator on ${key} requires a non-empty array`;
|
|
129
|
+
}
|
|
127
130
|
const OPERATOR = error.coded({
|
|
128
131
|
operator_unknown,
|
|
129
132
|
operator_empty,
|
|
130
133
|
wrong_type,
|
|
131
134
|
operator_scalar,
|
|
135
|
+
operator_empty_in,
|
|
132
136
|
});
|
|
133
137
|
function sort_empty() {
|
|
134
138
|
return t `empty sort`;
|
|
@@ -163,6 +167,12 @@ function where_invalid_value(field, value) {
|
|
|
163
167
|
function set_empty() {
|
|
164
168
|
return t `empty set on update`;
|
|
165
169
|
}
|
|
170
|
+
function offset_invalid() {
|
|
171
|
+
return t `offset must be a non-negative integer`;
|
|
172
|
+
}
|
|
173
|
+
function offset_requires_limit() {
|
|
174
|
+
return t `offset requires limit to be set`;
|
|
175
|
+
}
|
|
166
176
|
const QUERY = error.coded({
|
|
167
177
|
sort_empty,
|
|
168
178
|
sort_invalid,
|
|
@@ -175,6 +185,8 @@ const QUERY = error.coded({
|
|
|
175
185
|
where_invalid_value,
|
|
176
186
|
set_empty,
|
|
177
187
|
limit_invalid,
|
|
188
|
+
offset_invalid,
|
|
189
|
+
offset_requires_limit,
|
|
178
190
|
});
|
|
179
191
|
function relation_unknown(relation) {
|
|
180
192
|
return t `unknown relation ${relation}`;
|
|
@@ -182,13 +194,17 @@ function relation_unknown(relation) {
|
|
|
182
194
|
function relation_requires_pk(type) {
|
|
183
195
|
return t `relation loading requires ${type} primary key`;
|
|
184
196
|
}
|
|
185
|
-
function
|
|
186
|
-
return t `relation ${
|
|
197
|
+
function relation_table_mismatch(expected, actual) {
|
|
198
|
+
return t `relation table mismatch: expected ${expected}, got ${actual}`;
|
|
199
|
+
}
|
|
200
|
+
function relation_store_required(name) {
|
|
201
|
+
return t `relation ${name} requires a store`;
|
|
187
202
|
}
|
|
188
203
|
const RELATION = error.coded({
|
|
189
204
|
relation_unknown,
|
|
190
205
|
relation_requires_pk,
|
|
191
|
-
|
|
206
|
+
relation_table_mismatch,
|
|
207
|
+
relation_store_required,
|
|
192
208
|
});
|
|
193
209
|
function option_unknown(option) {
|
|
194
210
|
return t `unknown option ${option}`;
|
|
@@ -213,6 +229,12 @@ function unapplied_migrations() {
|
|
|
213
229
|
— Show migration status ${"npx primate migrate:status"}
|
|
214
230
|
- Apply pending migrations ${"npx primate migrate:apply"}`;
|
|
215
231
|
}
|
|
232
|
+
function sql_placeholder_missing(key) {
|
|
233
|
+
return t `input key ${key} has no matching placeholder in query`;
|
|
234
|
+
}
|
|
235
|
+
function sql_input_missing(key) {
|
|
236
|
+
return t `query placeholder ${key} has no matching input key`;
|
|
237
|
+
}
|
|
216
238
|
const MISC = error.coded({
|
|
217
239
|
option_unknown,
|
|
218
240
|
identifier_invalid,
|
|
@@ -221,6 +243,8 @@ const MISC = error.coded({
|
|
|
221
243
|
migration_directory_missing,
|
|
222
244
|
migration_store_conflict,
|
|
223
245
|
unapplied_migrations,
|
|
246
|
+
sql_placeholder_missing,
|
|
247
|
+
sql_input_missing,
|
|
224
248
|
});
|
|
225
249
|
const errors = {
|
|
226
250
|
...STORE,
|
|
@@ -232,6 +256,6 @@ const errors = {
|
|
|
232
256
|
...RELATION,
|
|
233
257
|
...MISC,
|
|
234
258
|
};
|
|
235
|
-
export const Code =
|
|
259
|
+
export const Code = error.names(errors);
|
|
236
260
|
export default errors;
|
|
237
261
|
//# sourceMappingURL=errors.js.map
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import E from "#db/errors";
|
|
2
2
|
import store from "#db/migrate/store";
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import fs from "@rcompat/fs";
|
|
3
|
+
import cli from "@rcompat/cli";
|
|
4
|
+
import runtime from "@rcompat/runtime";
|
|
6
5
|
export default async function apply_migration() {
|
|
7
6
|
const Migration = await store();
|
|
8
|
-
await Migration.
|
|
7
|
+
await Migration.create();
|
|
9
8
|
const last = await Migration.find({ limit: 1, sort: { id: "desc" } });
|
|
10
9
|
const last_id = last.length === 0 ? 0 : last[0].id;
|
|
11
|
-
const root = await
|
|
10
|
+
const root = await runtime.projectRoot();
|
|
12
11
|
const migrations_dir = root.join("migrations");
|
|
13
12
|
if (!await migrations_dir.exists())
|
|
14
13
|
throw E.migration_directory_missing();
|
|
@@ -17,17 +16,17 @@ export default async function apply_migration() {
|
|
|
17
16
|
.filter(({ n }) => n > last_id)
|
|
18
17
|
.toSorted((a, b) => a.n - b.n);
|
|
19
18
|
if (files.length === 0) {
|
|
20
|
-
print("No pending migrations.\n");
|
|
19
|
+
cli.print("No pending migrations.\n");
|
|
21
20
|
return;
|
|
22
21
|
}
|
|
23
22
|
for (const { file, n } of files) {
|
|
24
23
|
const { default: migration } = await import(file.path);
|
|
25
24
|
await migration(Migration.db);
|
|
26
25
|
await Migration.insert({ id: n, applied: new Date() });
|
|
27
|
-
print(`Applied migration ${
|
|
26
|
+
cli.print(`Applied migration ${cli.fg.bold(file.name)}.\n`);
|
|
28
27
|
}
|
|
29
28
|
const plural = files.length === 1 ? "" : "s";
|
|
30
|
-
print(`Done. Applied ${files.length} migration${plural}.\n`);
|
|
31
|
-
|
|
29
|
+
cli.print(`Done. Applied ${files.length} migration${plural}.\n`);
|
|
30
|
+
runtime.exit();
|
|
32
31
|
}
|
|
33
32
|
//# sourceMappingURL=apply.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import runtime from "@rcompat/runtime";
|
|
2
2
|
import esbuild from "esbuild";
|
|
3
3
|
export default async (contents) => {
|
|
4
|
-
const root = await
|
|
4
|
+
const root = await runtime.projectRoot();
|
|
5
5
|
const id = Date.now();
|
|
6
6
|
const entrypoint = root.join(`.migrate-in-${id}.js`);
|
|
7
7
|
const out = root.join(`.migrate-out-${id}.js`);
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import E from "#db/errors";
|
|
2
2
|
import bundle from "#db/migrate/bundle";
|
|
3
3
|
import toMigrationStore from "#db/migrate/store";
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import is_cancel from "@rcompat/cli/prompts/is-cancel";
|
|
7
|
-
import text from "@rcompat/cli/prompts/text";
|
|
8
|
-
import fs from "@rcompat/fs";
|
|
4
|
+
import cli from "@rcompat/cli";
|
|
5
|
+
import runtime from "@rcompat/runtime";
|
|
9
6
|
import string from "@rcompat/string";
|
|
10
7
|
function generate_migration(diffs) {
|
|
11
8
|
const lines = ["export default async db => {"];
|
|
@@ -16,13 +13,13 @@ function generate_migration(diffs) {
|
|
|
16
13
|
.map(([k, v]) => ` ${k}: "${v}"`)
|
|
17
14
|
.join(",\n");
|
|
18
15
|
const options = `{ name: "${store.pk}", generate: true }`;
|
|
19
|
-
lines.push(` await db.schema.create("${store.
|
|
16
|
+
lines.push(` await db.schema.create("${store.table}", ${options}, {`);
|
|
20
17
|
lines.push(`${types}`);
|
|
21
18
|
lines.push(" });");
|
|
22
19
|
}
|
|
23
20
|
else {
|
|
24
21
|
const { store, diff } = entry;
|
|
25
|
-
lines.push(` await db.schema.alter("${store.
|
|
22
|
+
lines.push(` await db.schema.alter("${store.table}", {`);
|
|
26
23
|
lines.push(` add: { ${Object.entries(diff.add).map(([k, v]) => `${k}: "${v}"`).join(", ")} },`);
|
|
27
24
|
lines.push(` drop: [${diff.drop.map(f => `"${f}"`).join(", ")}],`);
|
|
28
25
|
lines.push(` rename: [${diff.rename.map(([f, t]) => `["${f}", "${t}"]`).join(", ")}],`);
|
|
@@ -33,7 +30,7 @@ function generate_migration(diffs) {
|
|
|
33
30
|
return lines.join("\n");
|
|
34
31
|
}
|
|
35
32
|
export default async function create_migration(desc) {
|
|
36
|
-
const root = await
|
|
33
|
+
const root = await runtime.projectRoot();
|
|
37
34
|
const migrations = root.join("migrations");
|
|
38
35
|
// discover store files
|
|
39
36
|
const stores_dir = root.join("stores");
|
|
@@ -48,7 +45,7 @@ export default async function create_migration(desc) {
|
|
|
48
45
|
let next = 1;
|
|
49
46
|
if (await migrations.exists()) {
|
|
50
47
|
const Migration = await toMigrationStore();
|
|
51
|
-
await Migration.
|
|
48
|
+
await Migration.create();
|
|
52
49
|
const last = await Migration.find({ limit: 1, sort: { id: "desc" } });
|
|
53
50
|
const last_id = last.length === 0 ? 0 : last[0].id;
|
|
54
51
|
const files = await migrations.files({ filter: /\d+-.*\.ts$/ });
|
|
@@ -60,6 +57,7 @@ export default async function create_migration(desc) {
|
|
|
60
57
|
// generate virtual entry
|
|
61
58
|
const entry = store_files.map((f, i) => `import s${i} from "${f.path}";`).join("\n") + `\nexport default [
|
|
62
59
|
${store_files.map((_, i) => `s${i}`).join(",\n ")}\n];`;
|
|
60
|
+
console.log("entry", entry);
|
|
63
61
|
const stores = await bundle(entry);
|
|
64
62
|
const diffs = [];
|
|
65
63
|
const seen = new Set();
|
|
@@ -74,8 +72,8 @@ export default async function create_migration(desc) {
|
|
|
74
72
|
continue;
|
|
75
73
|
seen.add(store.id);
|
|
76
74
|
migration_stores.push(store);
|
|
77
|
-
const existing = names.get(store.
|
|
78
|
-
names.set(store.
|
|
75
|
+
const existing = names.get(store.table) ?? [];
|
|
76
|
+
names.set(store.table, [...existing, file.name]);
|
|
79
77
|
}
|
|
80
78
|
const conflicts = [...names].filter(([, files]) => files.length > 1);
|
|
81
79
|
if (conflicts.length > 0) {
|
|
@@ -85,7 +83,7 @@ export default async function create_migration(desc) {
|
|
|
85
83
|
throw E.migration_store_conflict(messages);
|
|
86
84
|
}
|
|
87
85
|
for (const store of migration_stores) {
|
|
88
|
-
const current = await store.db.schema.introspect(store.
|
|
86
|
+
const current = await store.db.schema.introspect(store.table, store.pk);
|
|
89
87
|
// table doesn't exist yet, create
|
|
90
88
|
if (current === null) {
|
|
91
89
|
diffs.push({
|
|
@@ -112,7 +110,7 @@ export default async function create_migration(desc) {
|
|
|
112
110
|
if (diff_entry.op !== "alter")
|
|
113
111
|
continue;
|
|
114
112
|
const { diff, store } = diff_entry;
|
|
115
|
-
const current = await store.db.schema.introspect(store.
|
|
113
|
+
const current = await store.db.schema.introspect(store.table, store.pk);
|
|
116
114
|
const confirmed_renames = [];
|
|
117
115
|
const confirmed_drops = [];
|
|
118
116
|
for (const dropped of diff.drop) {
|
|
@@ -125,13 +123,13 @@ export default async function create_migration(desc) {
|
|
|
125
123
|
continue;
|
|
126
124
|
}
|
|
127
125
|
for (const added of matching_added) {
|
|
128
|
-
const d =
|
|
129
|
-
const a =
|
|
130
|
-
const answer = await text({
|
|
126
|
+
const d = cli.fg.bold(dropped);
|
|
127
|
+
const a = cli.fg.bold(added);
|
|
128
|
+
const answer = await cli.prompt.text({
|
|
131
129
|
message: `${d} was removed and ${a} was `
|
|
132
130
|
+ `added with a compatible type. Rename ${d} → ${a}? (y/N)`,
|
|
133
131
|
});
|
|
134
|
-
if (!
|
|
132
|
+
if (!cli.prompt.isCancel(answer) && answer.toLowerCase() === "y") {
|
|
135
133
|
confirmed_renames.push([dropped, added]);
|
|
136
134
|
delete diff.add[added];
|
|
137
135
|
}
|
|
@@ -144,7 +142,7 @@ export default async function create_migration(desc) {
|
|
|
144
142
|
diff.drop = confirmed_drops;
|
|
145
143
|
}
|
|
146
144
|
if (diffs.length === 0) {
|
|
147
|
-
print("No schema changes detected.\n");
|
|
145
|
+
cli.print("No schema changes detected.\n");
|
|
148
146
|
return;
|
|
149
147
|
}
|
|
150
148
|
if (!await migrations.exists())
|
|
@@ -152,8 +150,8 @@ export default async function create_migration(desc) {
|
|
|
152
150
|
const content = generate_migration(diffs);
|
|
153
151
|
const filename = `${next}-${string.toSlug(desc)}.ts`;
|
|
154
152
|
await migrations.join(filename).write(content);
|
|
155
|
-
print(`Created ${
|
|
156
|
-
|
|
153
|
+
cli.print(`Created ${cli.fg.bold(`migrations/${filename}`)}.\n`);
|
|
154
|
+
runtime.exit();
|
|
157
155
|
}
|
|
158
156
|
;
|
|
159
157
|
//# sourceMappingURL=create.js.map
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import store from "#db/migrate/store";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import fs from "@rcompat/fs";
|
|
2
|
+
import cli from "@rcompat/cli";
|
|
3
|
+
import runtime from "@rcompat/runtime";
|
|
5
4
|
export default async function status_migration() {
|
|
6
|
-
const root = await
|
|
5
|
+
const root = await runtime.projectRoot();
|
|
7
6
|
const migrations_dir = root.join("migrations");
|
|
8
7
|
const Migration = await store();
|
|
9
|
-
await Migration.
|
|
8
|
+
await Migration.create();
|
|
10
9
|
const applied = await Migration.find({
|
|
11
10
|
limit: 3,
|
|
12
11
|
sort: { id: "desc" },
|
|
@@ -23,16 +22,16 @@ export default async function status_migration() {
|
|
|
23
22
|
const last_applied = applied.toReversed();
|
|
24
23
|
for (const { id, applied: date } of last_applied) {
|
|
25
24
|
const file = files.find(f => f.n === id);
|
|
26
|
-
print(`${
|
|
25
|
+
cli.print(`${cli.fg.green("Applied")} ${file?.name ?? "unknown"} (${date.toISOString()})\n`);
|
|
27
26
|
}
|
|
28
27
|
if (last_applied.length > 0 && pending.length > 0) {
|
|
29
|
-
print("---\n");
|
|
28
|
+
cli.print("---\n");
|
|
30
29
|
}
|
|
31
|
-
for (const { name
|
|
32
|
-
print(`${
|
|
30
|
+
for (const { name } of pending) {
|
|
31
|
+
cli.print(`${cli.fg.yellow("Pending")} ${cli.fg.bold(name)}\n`);
|
|
33
32
|
}
|
|
34
33
|
if (last_applied.length === 0 && pending.length === 0) {
|
|
35
|
-
print("No migrations found.\n");
|
|
34
|
+
cli.print("No migrations found.\n");
|
|
36
35
|
}
|
|
37
36
|
}
|
|
38
37
|
//# sourceMappingURL=status.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export default function migration_store(): Promise<import("
|
|
2
|
-
id: import("../../
|
|
1
|
+
export default function migration_store(): Promise<import("../../store/Store.js").default<{
|
|
2
|
+
id: import("../../store/PrimaryKey.js").default<import("pema").UintType<"u16">>;
|
|
3
3
|
applied: import("pema").DateType;
|
|
4
|
-
},
|
|
4
|
+
}, string>>;
|
|
5
5
|
//# sourceMappingURL=store.d.ts.map
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import bundle from "#db/migrate/bundle";
|
|
2
2
|
import E from "#errors";
|
|
3
|
-
import key from "#
|
|
4
|
-
import store from "#
|
|
5
|
-
import
|
|
3
|
+
import key from "#store/key";
|
|
4
|
+
import store from "#store";
|
|
5
|
+
import runtime from "@rcompat/runtime";
|
|
6
6
|
import p from "pema";
|
|
7
7
|
export default async function migration_store() {
|
|
8
|
-
const root = await
|
|
8
|
+
const root = await runtime.projectRoot();
|
|
9
9
|
const { path } = await (async () => {
|
|
10
10
|
const ts = root.join("config", "app.ts");
|
|
11
11
|
if (await ts.exists())
|
|
@@ -22,7 +22,7 @@ export default async function migration_store() {
|
|
|
22
22
|
throw E.config_missing("db.migrations");
|
|
23
23
|
const { table, db } = migrations_config;
|
|
24
24
|
return store({
|
|
25
|
-
|
|
25
|
+
table,
|
|
26
26
|
db,
|
|
27
27
|
schema: {
|
|
28
28
|
id: key.primary(p.u16, { generate: false }),
|