on-zero 0.4.1 → 0.4.3
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/dist/cjs/generate-helpers.cjs +309 -0
- package/dist/cjs/generate-helpers.native.js +451 -0
- package/dist/cjs/generate-helpers.native.js.map +1 -0
- package/dist/cjs/generate-lite.cjs +150 -0
- package/dist/cjs/generate-lite.native.js +269 -0
- package/dist/cjs/generate-lite.native.js.map +1 -0
- package/dist/cjs/generate-lite.test.cjs +229 -0
- package/dist/cjs/generate-lite.test.native.js +234 -0
- package/dist/cjs/generate-lite.test.native.js.map +1 -0
- package/dist/cjs/generate.cjs +16 -285
- package/dist/cjs/generate.native.js +18 -432
- package/dist/cjs/generate.native.js.map +1 -1
- package/dist/esm/generate-helpers.mjs +272 -0
- package/dist/esm/generate-helpers.mjs.map +1 -0
- package/dist/esm/generate-helpers.native.js +411 -0
- package/dist/esm/generate-helpers.native.js.map +1 -0
- package/dist/esm/generate-lite.mjs +127 -0
- package/dist/esm/generate-lite.mjs.map +1 -0
- package/dist/esm/generate-lite.native.js +243 -0
- package/dist/esm/generate-lite.native.js.map +1 -0
- package/dist/esm/generate-lite.test.mjs +230 -0
- package/dist/esm/generate-lite.test.mjs.map +1 -0
- package/dist/esm/generate-lite.test.native.js +232 -0
- package/dist/esm/generate-lite.test.native.js.map +1 -0
- package/dist/esm/generate.mjs +6 -275
- package/dist/esm/generate.mjs.map +1 -1
- package/dist/esm/generate.native.js +9 -423
- package/dist/esm/generate.native.js.map +1 -1
- package/package.json +7 -2
- package/src/generate-helpers.ts +440 -0
- package/src/generate-lite.test.ts +310 -0
- package/src/generate-lite.ts +333 -0
- package/src/generate.ts +23 -415
- package/types/generate-helpers.d.ts +42 -0
- package/types/generate-helpers.d.ts.map +1 -0
- package/types/generate-lite.d.ts +40 -0
- package/types/generate-lite.d.ts.map +1 -0
- package/types/generate-lite.test.d.ts +2 -0
- package/types/generate-lite.test.d.ts.map +1 -0
- package/types/generate.d.ts +1 -6
- package/types/generate.d.ts.map +1 -1
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: !0
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
__copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
21
|
+
value: !0
|
|
22
|
+
}), mod);
|
|
23
|
+
var generate_lite_exports = {};
|
|
24
|
+
__export(generate_lite_exports, {
|
|
25
|
+
generateLite: () => generateLite
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(generate_lite_exports);
|
|
28
|
+
var import_generate_helpers = require("./generate-helpers.native.js");
|
|
29
|
+
function stripTrailingSlash(s) {
|
|
30
|
+
return s.endsWith("/") ? s.slice(0, -1) : s;
|
|
31
|
+
}
|
|
32
|
+
function baseName(path, ext) {
|
|
33
|
+
var idx = path.lastIndexOf("/"),
|
|
34
|
+
base = idx >= 0 ? path.slice(idx + 1) : path;
|
|
35
|
+
return ext && base.endsWith(ext) && (base = base.slice(0, -ext.length)), base;
|
|
36
|
+
}
|
|
37
|
+
function listDirectTsFiles(files, dirPrefix) {
|
|
38
|
+
var prefix = stripTrailingSlash(dirPrefix) + "/",
|
|
39
|
+
out = [],
|
|
40
|
+
_iteratorNormalCompletion = !0,
|
|
41
|
+
_didIteratorError = !1,
|
|
42
|
+
_iteratorError = void 0;
|
|
43
|
+
try {
|
|
44
|
+
for (var _iterator = Object.keys(files)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) {
|
|
45
|
+
var path = _step.value;
|
|
46
|
+
if (path.startsWith(prefix)) {
|
|
47
|
+
var rest = path.slice(prefix.length);
|
|
48
|
+
rest.includes("/") || rest.endsWith(".ts") && (rest.endsWith(".d.ts") || out.push(path));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
} catch (err) {
|
|
52
|
+
_didIteratorError = !0, _iteratorError = err;
|
|
53
|
+
} finally {
|
|
54
|
+
try {
|
|
55
|
+
!_iteratorNormalCompletion && _iterator.return != null && _iterator.return();
|
|
56
|
+
} finally {
|
|
57
|
+
if (_didIteratorError) throw _iteratorError;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return out.sort();
|
|
61
|
+
}
|
|
62
|
+
function generateLite(opts) {
|
|
63
|
+
var {
|
|
64
|
+
files,
|
|
65
|
+
parse
|
|
66
|
+
} = opts,
|
|
67
|
+
baseDir = stripTrailingSlash(opts.dir),
|
|
68
|
+
modelsDirName;
|
|
69
|
+
if (opts.modelsDir) modelsDirName = opts.modelsDir;else {
|
|
70
|
+
var mutationsPrefix = `${baseDir}/mutations/`,
|
|
71
|
+
hasMutationsDir = Object.keys(files).some(function (p) {
|
|
72
|
+
return p.startsWith(mutationsPrefix);
|
|
73
|
+
});
|
|
74
|
+
modelsDirName = hasMutationsDir ? "mutations" : "models";
|
|
75
|
+
}
|
|
76
|
+
var modelsDirPath = `${baseDir}/${modelsDirName}`,
|
|
77
|
+
queriesDirPath = `${baseDir}/queries`,
|
|
78
|
+
modelFilePaths = listDirectTsFiles(files, modelsDirPath),
|
|
79
|
+
queryFilePaths = listDirectTsFiles(files, queriesDirPath),
|
|
80
|
+
allModelMutations = [],
|
|
81
|
+
modelNamesWithSchema = [],
|
|
82
|
+
_iteratorNormalCompletion = !0,
|
|
83
|
+
_didIteratorError = !1,
|
|
84
|
+
_iteratorError = void 0;
|
|
85
|
+
try {
|
|
86
|
+
for (var _iterator = modelFilePaths[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) {
|
|
87
|
+
var filePath = _step.value,
|
|
88
|
+
modelName = baseName(filePath, ".ts"),
|
|
89
|
+
content = files[filePath],
|
|
90
|
+
parsed = parse(content, filePath),
|
|
91
|
+
_parsed_mutations_,
|
|
92
|
+
mutationExport = (_parsed_mutations_ = parsed.mutations[0]) !== null && _parsed_mutations_ !== void 0 ? _parsed_mutations_ : null,
|
|
93
|
+
columns = {},
|
|
94
|
+
primaryKeys = [],
|
|
95
|
+
hasSchema = !1;
|
|
96
|
+
if (mutationExport?.schema) {
|
|
97
|
+
hasSchema = !0, modelNamesWithSchema.push(modelName);
|
|
98
|
+
var _iteratorNormalCompletion1 = !0,
|
|
99
|
+
_didIteratorError1 = !1,
|
|
100
|
+
_iteratorError1 = void 0;
|
|
101
|
+
try {
|
|
102
|
+
for (var _iterator1 = mutationExport.schema.primaryKeys[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = !0) {
|
|
103
|
+
var pk = _step1.value;
|
|
104
|
+
primaryKeys.push(pk);
|
|
105
|
+
}
|
|
106
|
+
} catch (err) {
|
|
107
|
+
_didIteratorError1 = !0, _iteratorError1 = err;
|
|
108
|
+
} finally {
|
|
109
|
+
try {
|
|
110
|
+
!_iteratorNormalCompletion1 && _iterator1.return != null && _iterator1.return();
|
|
111
|
+
} finally {
|
|
112
|
+
if (_didIteratorError1) throw _iteratorError1;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
var _iteratorNormalCompletion2 = !0,
|
|
116
|
+
_didIteratorError2 = !1,
|
|
117
|
+
_iteratorError2 = void 0;
|
|
118
|
+
try {
|
|
119
|
+
for (var _iterator2 = mutationExport.schema.columns[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = !0) {
|
|
120
|
+
var col = _step2.value;
|
|
121
|
+
columns[col.name] = (0, import_generate_helpers.parseColumnType)(col.builderText);
|
|
122
|
+
}
|
|
123
|
+
} catch (err) {
|
|
124
|
+
_didIteratorError2 = !0, _iteratorError2 = err;
|
|
125
|
+
} finally {
|
|
126
|
+
try {
|
|
127
|
+
!_iteratorNormalCompletion2 && _iterator2.return != null && _iterator2.return();
|
|
128
|
+
} finally {
|
|
129
|
+
if (_didIteratorError2) throw _iteratorError2;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
var hasCRUD = hasSchema && mutationExport !== null,
|
|
134
|
+
_mutationExport_handlers,
|
|
135
|
+
custom = ((_mutationExport_handlers = mutationExport?.handlers) !== null && _mutationExport_handlers !== void 0 ? _mutationExport_handlers : []).map(function (h) {
|
|
136
|
+
if (h.paramTypeText == null) return {
|
|
137
|
+
name: h.name,
|
|
138
|
+
paramType: "void",
|
|
139
|
+
valibotCode: ""
|
|
140
|
+
};
|
|
141
|
+
var paramType2 = h.paramTypeText.trim();
|
|
142
|
+
if (paramType2 === "unknown") return {
|
|
143
|
+
name: h.name,
|
|
144
|
+
paramType: "unknown",
|
|
145
|
+
valibotCode: ""
|
|
146
|
+
};
|
|
147
|
+
var valibotCode2 = null;
|
|
148
|
+
try {
|
|
149
|
+
valibotCode2 = (0, import_generate_helpers.parseTypeString)(paramType2);
|
|
150
|
+
} catch {
|
|
151
|
+
valibotCode2 = null;
|
|
152
|
+
}
|
|
153
|
+
return {
|
|
154
|
+
name: h.name,
|
|
155
|
+
paramType: paramType2,
|
|
156
|
+
valibotCode: valibotCode2 ?? "v.unknown()"
|
|
157
|
+
};
|
|
158
|
+
});
|
|
159
|
+
allModelMutations.push({
|
|
160
|
+
modelName,
|
|
161
|
+
hasCRUD,
|
|
162
|
+
columns,
|
|
163
|
+
primaryKeys,
|
|
164
|
+
custom
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
} catch (err) {
|
|
168
|
+
_didIteratorError = !0, _iteratorError = err;
|
|
169
|
+
} finally {
|
|
170
|
+
try {
|
|
171
|
+
!_iteratorNormalCompletion && _iterator.return != null && _iterator.return();
|
|
172
|
+
} finally {
|
|
173
|
+
if (_didIteratorError) throw _iteratorError;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
var allQueries = [],
|
|
177
|
+
_iteratorNormalCompletion3 = !0,
|
|
178
|
+
_didIteratorError3 = !1,
|
|
179
|
+
_iteratorError3 = void 0;
|
|
180
|
+
try {
|
|
181
|
+
for (var _iterator3 = queryFilePaths[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = !0) {
|
|
182
|
+
var filePath1 = _step3.value,
|
|
183
|
+
fileBaseName = baseName(filePath1, ".ts"),
|
|
184
|
+
content1 = files[filePath1],
|
|
185
|
+
parsed1 = parse(content1, filePath1),
|
|
186
|
+
_iteratorNormalCompletion4 = !0,
|
|
187
|
+
_didIteratorError4 = !1,
|
|
188
|
+
_iteratorError4 = void 0;
|
|
189
|
+
try {
|
|
190
|
+
for (var _iterator4 = parsed1.queries[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = !0) {
|
|
191
|
+
var q = _step4.value;
|
|
192
|
+
if (q.name !== "permission") {
|
|
193
|
+
if (q.paramTypeText == null) {
|
|
194
|
+
allQueries.push({
|
|
195
|
+
name: q.name,
|
|
196
|
+
params: "void",
|
|
197
|
+
valibotCode: "",
|
|
198
|
+
sourceFile: fileBaseName
|
|
199
|
+
});
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
var paramType = q.paramTypeText.trim(),
|
|
203
|
+
valibotCode = null;
|
|
204
|
+
try {
|
|
205
|
+
valibotCode = (0, import_generate_helpers.parseTypeString)(paramType);
|
|
206
|
+
} catch {
|
|
207
|
+
valibotCode = null;
|
|
208
|
+
}
|
|
209
|
+
allQueries.push({
|
|
210
|
+
name: q.name,
|
|
211
|
+
params: paramType,
|
|
212
|
+
valibotCode: valibotCode ?? "v.unknown()",
|
|
213
|
+
sourceFile: fileBaseName
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
} catch (err) {
|
|
218
|
+
_didIteratorError4 = !0, _iteratorError4 = err;
|
|
219
|
+
} finally {
|
|
220
|
+
try {
|
|
221
|
+
!_iteratorNormalCompletion4 && _iterator4.return != null && _iterator4.return();
|
|
222
|
+
} finally {
|
|
223
|
+
if (_didIteratorError4) throw _iteratorError4;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
} catch (err) {
|
|
228
|
+
_didIteratorError3 = !0, _iteratorError3 = err;
|
|
229
|
+
} finally {
|
|
230
|
+
try {
|
|
231
|
+
!_iteratorNormalCompletion3 && _iterator3.return != null && _iterator3.return();
|
|
232
|
+
} finally {
|
|
233
|
+
if (_didIteratorError3) throw _iteratorError3;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
var modelNames = modelFilePaths.map(function (p) {
|
|
237
|
+
return baseName(p, ".ts");
|
|
238
|
+
}),
|
|
239
|
+
out = {};
|
|
240
|
+
out["models.ts"] = (0, import_generate_helpers.generateModelsFile)(modelNames, modelsDirName), modelNamesWithSchema.length > 0 && (out["types.ts"] = (0, import_generate_helpers.generateTypesFile)(modelNamesWithSchema), out["tables.ts"] = (0, import_generate_helpers.generateTablesFile)(modelNamesWithSchema, modelsDirName)), out["README.md"] = (0, import_generate_helpers.generateReadmeFile)(), queryFilePaths.length > 0 && (out["groupedQueries.ts"] = (0, import_generate_helpers.generateGroupedQueriesFile)(allQueries), out["syncedQueries.ts"] = (0, import_generate_helpers.generateSyncedQueriesFile)(allQueries)), allModelMutations.length > 0 && (out["syncedMutations.ts"] = (0, import_generate_helpers.generateSyncedMutationsFile)(allModelMutations));
|
|
241
|
+
var mutationCount = 0,
|
|
242
|
+
_iteratorNormalCompletion5 = !0,
|
|
243
|
+
_didIteratorError5 = !1,
|
|
244
|
+
_iteratorError5 = void 0;
|
|
245
|
+
try {
|
|
246
|
+
for (var _loop = function () {
|
|
247
|
+
var m = _step5.value;
|
|
248
|
+
m.hasCRUD && (mutationCount += 3), mutationCount += m.custom.filter(function (mut) {
|
|
249
|
+
return !m.hasCRUD || !["insert", "update", "delete", "upsert"].includes(mut.name);
|
|
250
|
+
}).length;
|
|
251
|
+
}, _iterator5 = allModelMutations[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = !0) _loop();
|
|
252
|
+
} catch (err) {
|
|
253
|
+
_didIteratorError5 = !0, _iteratorError5 = err;
|
|
254
|
+
} finally {
|
|
255
|
+
try {
|
|
256
|
+
!_iteratorNormalCompletion5 && _iterator5.return != null && _iterator5.return();
|
|
257
|
+
} finally {
|
|
258
|
+
if (_didIteratorError5) throw _iteratorError5;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return {
|
|
262
|
+
files: out,
|
|
263
|
+
modelCount: modelNames.length,
|
|
264
|
+
queryCount: allQueries.length,
|
|
265
|
+
mutationCount,
|
|
266
|
+
schemaCount: modelNamesWithSchema.length
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
//# sourceMappingURL=generate-lite.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","generate_lite_exports","__export","generateLite","module","exports","import_generate_helpers","require","stripTrailingSlash","s","endsWith","slice","baseName","path","ext","idx","lastIndexOf","base","length","listDirectTsFiles","files","dirPrefix","prefix","out","_iteratorNormalCompletion","_didIteratorError","_iteratorError","_iterator","Object","keys","Symbol","iterator","_step","next","done","startsWith","rest","includes","push","err","return","sort","opts","parse","baseDir","dir","modelsDirName","modelsDir","mutationsPrefix","hasMutationsDir","some","p","modelsDirPath","queriesDirPath","modelFilePaths","queryFilePaths","allModelMutations","modelNamesWithSchema","filePath","modelName","content","parsed","_parsed_mutations_","mutationExport","mutations","columns","primaryKeys","hasSchema","schema","_iteratorNormalCompletion1","_didIteratorError1","_iteratorError1","_iterator1","_step1","pk","_iteratorNormalCompletion2","_didIteratorError2","_iteratorError2","_iterator2","_step2","col","name","parseColumnType","builderText","hasCRUD","_mutationExport_handlers","custom","handlers","map","h","paramTypeText","paramType","valibotCode","paramType2","trim","valibotCode2","parseTypeString"],"sources":["../../src/generate-lite.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,qBAAA;AAAAC,QAAA,CAAAD,qBAAA;EAAAE,YAAA,EAAAA,CAAA,KAAAA;AAAA;AAgBAC,MAAA,CAAAC,OAAA,GAAAT,YAAA,CAUOK,qBAAA;AAuFP,IAAAK,uBAAS,GAAmBC,OAAmB;AAC7C,SAAOC,kBAAkBA,CAAAC,CAAE;EAC7B,OAAAA,CAAA,CAAAC,QAAA,QAAAD,CAAA,CAAAE,KAAA,UAAAF,CAAA;AAIA;AACE,SAAMG,QAAMA,CAAAC,IAAK,EAAAC,GAAA;EACjB,IAAIC,GAAA,GAAAF,IAAO,CAAAG,WAAW,CAAK;IAAMC,IAAA,GAAOF,GAAA,IAAI,IAAAF,IAAA,CAAAF,KAAA,CAAAI,GAAA,QAAAF,IAAA;EAC5C,OAAIC,GAAA,IAAOG,IAAA,CAAKP,QAAA,CAASI,GAAG,MAAGG,IAAA,GAAOA,IAAA,CAAKN,KAAA,CAAM,GAAG,CAACG,GAAA,CAAII,MAA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AAAC,UAAa,GAAAJ,CAAA,CAAAC,aAAe,CAAAI,IAAA;UAC5B,IAAAD,UAAY,gBACb;YACHZ,IAAA,EAAAQ,CAAA,CAAAR,IAAA;YACFU,SAAA;YAGMC,WAAa;UAGf;UAoBA,IAAAG,YAAgB;UACpB;YACQA,YAAS,OAAAzF,uBACf,CAAA0F,eAA0B,EAAAH,UAAA;UACvB,QAAS;YACVE,YAAA;UAGJ;UACE,OAAO;YACPd,IAAA,EAAYQ,CAAA,CAAAR,IAAA;YACZU,SAAY,EAAAE,UAAW;YACvBD,WAAA,EAAAG,YAAA;UACA;QACF;MACFvC,iBAAA,CAAAlB,IAAA","ignoreList":[]}
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
var import_vitest = require("vitest"),
|
|
2
|
+
import_generate_lite = require("./generate-lite.cjs");
|
|
3
|
+
function makeParse(table) {
|
|
4
|
+
return (_src, path) => {
|
|
5
|
+
const entry = table[path];
|
|
6
|
+
if (!entry) throw new Error(`no lite ast fixture for ${path}`);
|
|
7
|
+
return entry;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
const DIR = "/proj/src/data";
|
|
11
|
+
(0, import_vitest.describe)("generateLite", () => {
|
|
12
|
+
(0, import_vitest.test)("emits models.ts, syncedMutations.ts, and README.md from inline types", () => {
|
|
13
|
+
const files = {
|
|
14
|
+
[`${DIR}/models/todo.ts`]: "// fake source, parser returns fixture",
|
|
15
|
+
[`${DIR}/models/user.ts`]: "// fake source, parser returns fixture"
|
|
16
|
+
},
|
|
17
|
+
fixtures = {
|
|
18
|
+
[`${DIR}/models/todo.ts`]: {
|
|
19
|
+
mutations: [{
|
|
20
|
+
modelName: "todo",
|
|
21
|
+
handlers: [{
|
|
22
|
+
name: "toggle",
|
|
23
|
+
paramTypeText: "{ id: string; isActive: boolean }"
|
|
24
|
+
}, {
|
|
25
|
+
name: "rename",
|
|
26
|
+
paramTypeText: "{ id: string; title: string }"
|
|
27
|
+
}],
|
|
28
|
+
schema: null
|
|
29
|
+
}],
|
|
30
|
+
queries: []
|
|
31
|
+
},
|
|
32
|
+
[`${DIR}/models/user.ts`]: {
|
|
33
|
+
mutations: [{
|
|
34
|
+
modelName: "user",
|
|
35
|
+
handlers: [{
|
|
36
|
+
name: "finishOnboarding",
|
|
37
|
+
// null = no second param / void
|
|
38
|
+
paramTypeText: null
|
|
39
|
+
}],
|
|
40
|
+
schema: null
|
|
41
|
+
}],
|
|
42
|
+
queries: []
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
result = (0, import_generate_lite.generateLite)({
|
|
46
|
+
files,
|
|
47
|
+
dir: DIR,
|
|
48
|
+
parse: makeParse(fixtures)
|
|
49
|
+
});
|
|
50
|
+
(0, import_vitest.expect)(Object.keys(result.files).sort()).toEqual(["README.md", "models.ts", "syncedMutations.ts"]);
|
|
51
|
+
const models = result.files["models.ts"];
|
|
52
|
+
(0, import_vitest.expect)(models).toContain("import * as todo from '../models/todo'"), (0, import_vitest.expect)(models).toContain("import * as userPublic from '../models/user'"), (0, import_vitest.expect)(models).toContain("export const models = {");
|
|
53
|
+
const syncedMutations = result.files["syncedMutations.ts"];
|
|
54
|
+
(0, import_vitest.expect)(syncedMutations).toContain("toggle:"), (0, import_vitest.expect)(syncedMutations).toContain("v.object({"), (0, import_vitest.expect)(syncedMutations).toContain("id: v.string()"), (0, import_vitest.expect)(syncedMutations).toContain("isActive: v.boolean()"), (0, import_vitest.expect)(syncedMutations).toContain("rename:"), (0, import_vitest.expect)(syncedMutations).toContain("title: v.string()"), (0, import_vitest.expect)(syncedMutations).toContain("finishOnboarding: v.void_()"), (0, import_vitest.expect)(result.modelCount).toBe(2), (0, import_vitest.expect)(result.schemaCount).toBe(0), (0, import_vitest.expect)(result.mutationCount).toBe(3);
|
|
55
|
+
}), (0, import_vitest.test)("falls back to v.unknown() for type references", () => {
|
|
56
|
+
const files = {
|
|
57
|
+
[`${DIR}/models/post.ts`]: "// fake"
|
|
58
|
+
},
|
|
59
|
+
fixtures = {
|
|
60
|
+
[`${DIR}/models/post.ts`]: {
|
|
61
|
+
mutations: [{
|
|
62
|
+
modelName: "post",
|
|
63
|
+
handlers: [{
|
|
64
|
+
name: "archive",
|
|
65
|
+
// bare type reference — parseTypeString returns null, so
|
|
66
|
+
// generate-lite should fall back to v.unknown() rather than
|
|
67
|
+
// attempting cross-file type resolution.
|
|
68
|
+
paramTypeText: "ArchiveParams"
|
|
69
|
+
}, {
|
|
70
|
+
name: "publish",
|
|
71
|
+
// primitive, should resolve
|
|
72
|
+
paramTypeText: "string"
|
|
73
|
+
}],
|
|
74
|
+
schema: null
|
|
75
|
+
}],
|
|
76
|
+
queries: []
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
synced = (0, import_generate_lite.generateLite)({
|
|
80
|
+
files,
|
|
81
|
+
dir: DIR,
|
|
82
|
+
parse: makeParse(fixtures)
|
|
83
|
+
}).files["syncedMutations.ts"];
|
|
84
|
+
(0, import_vitest.expect)(synced).toContain("archive: v.unknown()"), (0, import_vitest.expect)(synced).toContain("publish: v.string()");
|
|
85
|
+
}), (0, import_vitest.test)("emits query files with v.unknown() fallback for references", () => {
|
|
86
|
+
const files = {
|
|
87
|
+
[`${DIR}/models/post.ts`]: "// fake",
|
|
88
|
+
[`${DIR}/queries/post.ts`]: "// fake"
|
|
89
|
+
},
|
|
90
|
+
fixtures = {
|
|
91
|
+
[`${DIR}/models/post.ts`]: {
|
|
92
|
+
mutations: [],
|
|
93
|
+
queries: []
|
|
94
|
+
},
|
|
95
|
+
[`${DIR}/queries/post.ts`]: {
|
|
96
|
+
mutations: [],
|
|
97
|
+
queries: [
|
|
98
|
+
// no-arg query → void
|
|
99
|
+
{
|
|
100
|
+
name: "allPosts",
|
|
101
|
+
paramTypeText: null
|
|
102
|
+
},
|
|
103
|
+
// inline object → real validator
|
|
104
|
+
{
|
|
105
|
+
name: "postById",
|
|
106
|
+
paramTypeText: "{ id: string }"
|
|
107
|
+
},
|
|
108
|
+
// primitive
|
|
109
|
+
{
|
|
110
|
+
name: "byAuthorId",
|
|
111
|
+
paramTypeText: "string"
|
|
112
|
+
},
|
|
113
|
+
// type reference → fallback
|
|
114
|
+
{
|
|
115
|
+
name: "filtered",
|
|
116
|
+
paramTypeText: "PostFilter"
|
|
117
|
+
},
|
|
118
|
+
// permission should be skipped
|
|
119
|
+
{
|
|
120
|
+
name: "permission",
|
|
121
|
+
paramTypeText: null
|
|
122
|
+
}]
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
result = (0, import_generate_lite.generateLite)({
|
|
126
|
+
files,
|
|
127
|
+
dir: DIR,
|
|
128
|
+
parse: makeParse(fixtures)
|
|
129
|
+
});
|
|
130
|
+
(0, import_vitest.expect)(result.files["groupedQueries.ts"]).toBeDefined(), (0, import_vitest.expect)(result.files["syncedQueries.ts"]).toBeDefined();
|
|
131
|
+
const grouped = result.files["groupedQueries.ts"];
|
|
132
|
+
(0, import_vitest.expect)(grouped).toContain("export * as post from '../queries/post'");
|
|
133
|
+
const synced = result.files["syncedQueries.ts"];
|
|
134
|
+
(0, import_vitest.expect)(synced).toContain("allPosts: defineQuery(() => Queries.post.allPosts())"), (0, import_vitest.expect)(synced).toContain("postById: defineQuery("), (0, import_vitest.expect)(synced).toContain("id: v.string()"), (0, import_vitest.expect)(synced).toContain("byAuthorId: defineQuery("), (0, import_vitest.expect)(synced).toMatch(/byAuthorId: defineQuery\(\s*v\.string\(\)/), (0, import_vitest.expect)(synced).toContain("filtered: defineQuery("), (0, import_vitest.expect)(synced).toMatch(/filtered: defineQuery\(\s*v\.unknown\(\)/), (0, import_vitest.expect)(synced).not.toContain("permission: defineQuery"), (0, import_vitest.expect)(result.queryCount).toBe(4);
|
|
135
|
+
}), (0, import_vitest.test)("emits types.ts and tables.ts when a model declares a schema inline", () => {
|
|
136
|
+
const files = {
|
|
137
|
+
[`${DIR}/models/task.ts`]: "// fake"
|
|
138
|
+
},
|
|
139
|
+
fixtures = {
|
|
140
|
+
[`${DIR}/models/task.ts`]: {
|
|
141
|
+
mutations: [{
|
|
142
|
+
modelName: "task",
|
|
143
|
+
handlers: [],
|
|
144
|
+
schema: {
|
|
145
|
+
tableName: "task",
|
|
146
|
+
primaryKeys: ["id"],
|
|
147
|
+
columns: [{
|
|
148
|
+
name: "id",
|
|
149
|
+
builderText: "string()"
|
|
150
|
+
}, {
|
|
151
|
+
name: "title",
|
|
152
|
+
builderText: "string()"
|
|
153
|
+
}, {
|
|
154
|
+
name: "priority",
|
|
155
|
+
builderText: "number()"
|
|
156
|
+
}, {
|
|
157
|
+
name: "done",
|
|
158
|
+
builderText: "boolean()"
|
|
159
|
+
}, {
|
|
160
|
+
name: "note",
|
|
161
|
+
builderText: "string().optional()"
|
|
162
|
+
}]
|
|
163
|
+
}
|
|
164
|
+
}],
|
|
165
|
+
queries: []
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
result = (0, import_generate_lite.generateLite)({
|
|
169
|
+
files,
|
|
170
|
+
dir: DIR,
|
|
171
|
+
parse: makeParse(fixtures)
|
|
172
|
+
});
|
|
173
|
+
(0, import_vitest.expect)(result.schemaCount).toBe(1), (0, import_vitest.expect)(result.files["types.ts"]).toBeDefined(), (0, import_vitest.expect)(result.files["tables.ts"]).toBeDefined();
|
|
174
|
+
const types = result.files["types.ts"];
|
|
175
|
+
(0, import_vitest.expect)(types).toContain("export type Task = TableInsertRow<typeof schema.task>");
|
|
176
|
+
const tables = result.files["tables.ts"];
|
|
177
|
+
(0, import_vitest.expect)(tables).toContain("export { schema as task } from '../models/task'");
|
|
178
|
+
const synced = result.files["syncedMutations.ts"];
|
|
179
|
+
(0, import_vitest.expect)(synced).toContain("insert:"), (0, import_vitest.expect)(synced).toContain("update:"), (0, import_vitest.expect)(synced).toContain("delete:"), (0, import_vitest.expect)(result.mutationCount).toBe(3);
|
|
180
|
+
}), (0, import_vitest.test)("ignores nested files and non-ts files inside the models directory", () => {
|
|
181
|
+
const files = {
|
|
182
|
+
[`${DIR}/models/post.ts`]: "// fake",
|
|
183
|
+
[`${DIR}/models/README.md`]: "not a model",
|
|
184
|
+
[`${DIR}/models/helpers/util.ts`]: "nested should be ignored",
|
|
185
|
+
[`${DIR}/models/post.d.ts`]: "declaration file, ignored"
|
|
186
|
+
},
|
|
187
|
+
fixtures = {
|
|
188
|
+
[`${DIR}/models/post.ts`]: {
|
|
189
|
+
mutations: [{
|
|
190
|
+
modelName: "post",
|
|
191
|
+
handlers: [],
|
|
192
|
+
schema: null
|
|
193
|
+
}],
|
|
194
|
+
queries: []
|
|
195
|
+
}
|
|
196
|
+
},
|
|
197
|
+
result = (0, import_generate_lite.generateLite)({
|
|
198
|
+
files,
|
|
199
|
+
dir: DIR,
|
|
200
|
+
parse: makeParse(fixtures)
|
|
201
|
+
});
|
|
202
|
+
(0, import_vitest.expect)(result.modelCount).toBe(1);
|
|
203
|
+
const models = result.files["models.ts"];
|
|
204
|
+
(0, import_vitest.expect)(models).toContain("import * as post from '../models/post'"), (0, import_vitest.expect)(models).not.toContain("util"), (0, import_vitest.expect)(models).not.toContain("README");
|
|
205
|
+
}), (0, import_vitest.test)("infers mutations/ directory when present", () => {
|
|
206
|
+
const files = {
|
|
207
|
+
[`${DIR}/mutations/post.ts`]: "// fake"
|
|
208
|
+
},
|
|
209
|
+
fixtures = {
|
|
210
|
+
[`${DIR}/mutations/post.ts`]: {
|
|
211
|
+
mutations: [{
|
|
212
|
+
modelName: "post",
|
|
213
|
+
handlers: [{
|
|
214
|
+
name: "publish",
|
|
215
|
+
paramTypeText: "{ id: string }"
|
|
216
|
+
}],
|
|
217
|
+
schema: null
|
|
218
|
+
}],
|
|
219
|
+
queries: []
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
models = (0, import_generate_lite.generateLite)({
|
|
223
|
+
files,
|
|
224
|
+
dir: DIR,
|
|
225
|
+
parse: makeParse(fixtures)
|
|
226
|
+
}).files["models.ts"];
|
|
227
|
+
(0, import_vitest.expect)(models).toContain("from '../mutations/post'");
|
|
228
|
+
});
|
|
229
|
+
});
|