gencow 0.1.162 → 0.1.163

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/bin/gencow.mjs CHANGED
@@ -210,11 +210,14 @@ const runStaticDeployRuntime = createStaticDeployRuntime({
210
210
  updateEnvLocalUrlImpl: updateEnvLocalUrl,
211
211
  });
212
212
  const runDeployCommand = createDeployCommand({
213
+ buildEnvImpl: buildEnv,
213
214
  cwdImpl: () => process.cwd(),
214
215
  drizzleKitCmdImpl: _drizzleKitCmd,
215
216
  existsSyncImpl: existsSync,
217
+ findServerRootImpl: findServerRoot,
216
218
  handleDeployReadonlySubcommandImpl: handleDeployReadonlySubcommand,
217
219
  isMonorepoImpl: isMonorepo,
220
+ loadConfigImpl: loadConfig,
218
221
  platformFetchImpl: platformFetch,
219
222
  processEnv: process.env,
220
223
  processRef: process,
package/core/index.js CHANGED
@@ -1102,14 +1102,285 @@ function getRegisteredMutations() {
1102
1102
  return [...mutationRegistry];
1103
1103
  }
1104
1104
 
1105
+ // ../core/src/v.ts
1106
+ var GencowValidationError = class extends Error {
1107
+ statusCode = 400;
1108
+ constructor(message) {
1109
+ super(message);
1110
+ this.name = "GencowValidationError";
1111
+ }
1112
+ };
1113
+ var GENCOW_OPTIONAL_INNER = /* @__PURE__ */ Symbol.for("gencow.v.optionalInner");
1114
+ function assertStandardResult(value) {
1115
+ return { value };
1116
+ }
1117
+ function failStandardResult(message) {
1118
+ return { issues: [{ message }] };
1119
+ }
1120
+ function readJsonSchemaFragment(validator) {
1121
+ const opt = validator[GENCOW_OPTIONAL_INNER];
1122
+ const target = opt ?? validator;
1123
+ const raw = target["~standard"]?.jsonSchema;
1124
+ if (raw === void 0) return {};
1125
+ return typeof raw === "function" ? raw() : raw;
1126
+ }
1127
+ function isOptionalValidator(validator) {
1128
+ return !!validator && Object.prototype.hasOwnProperty.call(validator, GENCOW_OPTIONAL_INNER);
1129
+ }
1130
+ function readGencowStandardJsonSchema(schema) {
1131
+ if (!schema || typeof schema !== "object" || !("~standard" in schema)) return void 0;
1132
+ const props = schema["~standard"];
1133
+ if (!props || props.vendor !== "gencow") return void 0;
1134
+ const raw = props.jsonSchema;
1135
+ if (raw === void 0) return void 0;
1136
+ return typeof raw === "function" ? raw() : raw;
1137
+ }
1138
+ function isRecord(value) {
1139
+ return typeof value === "object" && value !== null && !Array.isArray(value);
1140
+ }
1141
+ function isAllOptionalObjectSchema(schema) {
1142
+ const jsonSchema = readGencowStandardJsonSchema(schema);
1143
+ if (!isRecord(jsonSchema) || jsonSchema.type !== "object") return false;
1144
+ const required = jsonSchema.required;
1145
+ return required === void 0 || Array.isArray(required) && required.length === 0;
1146
+ }
1147
+ function normalizeMissingOptionalObjectInput(schema, value) {
1148
+ if (value !== void 0) return value;
1149
+ return isAllOptionalObjectSchema(schema) ? {} : value;
1150
+ }
1151
+ function matchesMimeType(fileType, pattern) {
1152
+ const normalizedFileType = fileType.split(";")[0].trim().toLowerCase();
1153
+ const normalizedPattern = pattern.trim().toLowerCase();
1154
+ if (normalizedPattern === "*/*") return true;
1155
+ if (normalizedPattern.endsWith("/*")) {
1156
+ const prefix = normalizedPattern.slice(0, -1);
1157
+ return normalizedFileType.startsWith(prefix);
1158
+ }
1159
+ return normalizedFileType === normalizedPattern;
1160
+ }
1161
+ function buildObjectJsonSchema(fields) {
1162
+ const properties = {};
1163
+ const required = [];
1164
+ for (const key of Object.keys(fields)) {
1165
+ const field = fields[key];
1166
+ properties[key] = readJsonSchemaFragment(field);
1167
+ if (!isOptionalValidator(field)) {
1168
+ required.push(key);
1169
+ }
1170
+ }
1171
+ return {
1172
+ type: "object",
1173
+ properties,
1174
+ ...required.length > 0 ? { required } : {}
1175
+ };
1176
+ }
1177
+ function createValidator(config) {
1178
+ const { parse, _type, jsonSchema } = config;
1179
+ const standard = {
1180
+ version: 1,
1181
+ vendor: "gencow",
1182
+ types: {},
1183
+ validate: async (value) => {
1184
+ try {
1185
+ return assertStandardResult(parse(value));
1186
+ } catch (e) {
1187
+ const message = e instanceof Error ? e.message : "Validation failed";
1188
+ return failStandardResult(message);
1189
+ }
1190
+ },
1191
+ ...jsonSchema !== void 0 ? { jsonSchema } : {}
1192
+ };
1193
+ return {
1194
+ parse,
1195
+ _type,
1196
+ "~standard": standard
1197
+ };
1198
+ }
1199
+ var v = {
1200
+ string() {
1201
+ return createValidator({
1202
+ parse: (val) => {
1203
+ if (typeof val !== "string") throw new Error(`Expected string, got ${typeof val}`);
1204
+ return val;
1205
+ },
1206
+ _type: "",
1207
+ jsonSchema: { type: "string" }
1208
+ });
1209
+ },
1210
+ number() {
1211
+ return createValidator({
1212
+ parse: (val) => {
1213
+ const n = typeof val === "string" ? Number(val) : val;
1214
+ if (typeof n !== "number" || isNaN(n)) throw new Error(`Expected number, got ${typeof val}`);
1215
+ return n;
1216
+ },
1217
+ _type: 0,
1218
+ jsonSchema: { type: "number" }
1219
+ });
1220
+ },
1221
+ boolean() {
1222
+ return createValidator({
1223
+ parse: (val) => {
1224
+ if (typeof val !== "boolean") throw new Error(`Expected boolean, got ${typeof val}`);
1225
+ return val;
1226
+ },
1227
+ _type: false,
1228
+ jsonSchema: { type: "boolean" }
1229
+ });
1230
+ },
1231
+ /** ISO / `Date` — used for Drizzle `timestamp` columns; codegen maps to `Date`. */
1232
+ dateTime() {
1233
+ return createValidator({
1234
+ parse: (val) => {
1235
+ if (val instanceof Date && !Number.isNaN(val.getTime())) return val;
1236
+ if (typeof val === "string") {
1237
+ const d = new Date(val);
1238
+ if (!Number.isNaN(d.getTime())) return d;
1239
+ }
1240
+ if (typeof val === "number" && Number.isFinite(val)) {
1241
+ const d = new Date(val);
1242
+ if (!Number.isNaN(d.getTime())) return d;
1243
+ }
1244
+ throw new Error(`Expected date, got ${typeof val}`);
1245
+ },
1246
+ _type: /* @__PURE__ */ new Date(0),
1247
+ jsonSchema: { type: "string", format: "date-time" }
1248
+ });
1249
+ },
1250
+ any() {
1251
+ return createValidator({
1252
+ parse: (val) => val,
1253
+ _type: null
1254
+ });
1255
+ },
1256
+ optional(inner) {
1257
+ const out = createValidator({
1258
+ parse: (val) => {
1259
+ if (val === void 0 || val === null) return void 0;
1260
+ return inner.parse(val);
1261
+ },
1262
+ _type: void 0,
1263
+ jsonSchema: readJsonSchemaFragment(inner)
1264
+ });
1265
+ out[GENCOW_OPTIONAL_INNER] = inner;
1266
+ return out;
1267
+ },
1268
+ nullable(inner) {
1269
+ return createValidator({
1270
+ parse: (val) => {
1271
+ if (val === null) return null;
1272
+ return inner.parse(val);
1273
+ },
1274
+ _type: null,
1275
+ jsonSchema: { anyOf: [readJsonSchemaFragment(inner), { type: "null" }] }
1276
+ });
1277
+ },
1278
+ object(fields) {
1279
+ return createValidator({
1280
+ parse: (val) => {
1281
+ if (val === void 0 && Object.values(fields).every((field) => isOptionalValidator(field))) {
1282
+ val = {};
1283
+ }
1284
+ if (typeof val !== "object" || val === null) throw new Error("Expected object");
1285
+ const result = {};
1286
+ for (const key in fields) {
1287
+ result[key] = fields[key].parse(val[key]);
1288
+ }
1289
+ return result;
1290
+ },
1291
+ _type: {},
1292
+ jsonSchema: buildObjectJsonSchema(fields)
1293
+ });
1294
+ },
1295
+ array(inner) {
1296
+ const items = readJsonSchemaFragment(inner);
1297
+ return createValidator({
1298
+ parse: (val) => {
1299
+ if (!Array.isArray(val)) throw new Error("Expected array");
1300
+ return val.map((item) => inner.parse(item));
1301
+ },
1302
+ _type: [],
1303
+ jsonSchema: { type: "array", items }
1304
+ });
1305
+ },
1306
+ /** Browser `File` / `Blob` for procedure multipart uploads. */
1307
+ file() {
1308
+ const base = createValidator({
1309
+ parse: (val) => {
1310
+ if (!(val instanceof Blob)) {
1311
+ throw new Error(`Expected file, got ${typeof val}`);
1312
+ }
1313
+ return val;
1314
+ },
1315
+ _type: null,
1316
+ jsonSchema: { type: "string", format: "binary", "x-gencow-type": "file" }
1317
+ });
1318
+ return Object.assign(base, {
1319
+ mime(mimeType) {
1320
+ return createValidator({
1321
+ parse: (val) => {
1322
+ const blob = base.parse(val);
1323
+ if (!matchesMimeType(blob.type, mimeType)) {
1324
+ throw new Error(
1325
+ `Expected a file of type ${mimeType} but got ${blob.type || "unknown"}`
1326
+ );
1327
+ }
1328
+ return blob;
1329
+ },
1330
+ _type: null,
1331
+ jsonSchema: {
1332
+ type: "string",
1333
+ format: "binary",
1334
+ "x-gencow-type": "file",
1335
+ "x-gencow-mime": mimeType
1336
+ }
1337
+ });
1338
+ }
1339
+ });
1340
+ }
1341
+ };
1342
+ function parseArgs(schema, args) {
1343
+ if (!schema) return args;
1344
+ if (typeof schema.parse === "function") {
1345
+ try {
1346
+ return schema.parse(normalizeMissingOptionalObjectInput(schema, args));
1347
+ } catch (e) {
1348
+ throw new GencowValidationError(e.message);
1349
+ }
1350
+ }
1351
+ if (typeof schema === "object" && schema !== null) {
1352
+ const schemaKeys = Object.keys(schema);
1353
+ if (schemaKeys.length === 0) return args;
1354
+ if (typeof args !== "object" || args === null) {
1355
+ throw new GencowValidationError("Expected an object for arguments");
1356
+ }
1357
+ const result = {};
1358
+ for (const key of schemaKeys) {
1359
+ const validator = schema[key];
1360
+ if (validator && typeof validator.parse === "function") {
1361
+ try {
1362
+ result[key] = validator.parse(args[key]);
1363
+ } catch (e) {
1364
+ throw new GencowValidationError(`Argument "${key}": ${e.message}`);
1365
+ }
1366
+ } else {
1367
+ result[key] = args[key];
1368
+ }
1369
+ }
1370
+ return result;
1371
+ }
1372
+ return args;
1373
+ }
1374
+
1105
1375
  // ../core/src/procedure.ts
1106
1376
  function hasStandardSchema2(schema) {
1107
1377
  return !!schema && typeof schema === "object" && "~standard" in schema && !!schema["~standard"] && typeof schema["~standard"].validate === "function";
1108
1378
  }
1109
- async function validateWithSchema(schema, value) {
1379
+ async function validateWithSchema(schema, value, options) {
1110
1380
  if (!schema) return value;
1381
+ const valueToValidate = options?.normalizeMissingOptionalObject ? normalizeMissingOptionalObjectInput(schema, value) : value;
1111
1382
  if (hasStandardSchema2(schema)) {
1112
- const result = await schema["~standard"].validate(value);
1383
+ const result = await schema["~standard"].validate(valueToValidate);
1113
1384
  if ("issues" in result && result.issues.length > 0) {
1114
1385
  throw new Error(result.issues[0]?.message ?? "Validation failed");
1115
1386
  }
@@ -1132,7 +1403,9 @@ function composeMiddlewares(middlewares, handler, inputSchema, outputSchema, inp
1132
1403
  idx = currentIdx;
1133
1404
  let currentInput = input;
1134
1405
  if (currentIdx === boundedInputValidationIndex) {
1135
- currentInput = await validateWithSchema(inputSchema, currentInput);
1406
+ currentInput = await validateWithSchema(inputSchema, currentInput, {
1407
+ normalizeMissingOptionalObject: true
1408
+ });
1136
1409
  }
1137
1410
  if (currentIdx === middlewares.length) {
1138
1411
  const output2 = await handler({ context, input: currentInput });
@@ -1743,249 +2016,6 @@ var WORKFLOW_WAKE_SIGNAL_PAYLOAD = JSON.stringify({ kind: "workflow" });
1743
2016
  // ../core/src/workflows-api.ts
1744
2017
  import { sql as sql3 } from "drizzle-orm";
1745
2018
 
1746
- // ../core/src/v.ts
1747
- var GencowValidationError = class extends Error {
1748
- statusCode = 400;
1749
- constructor(message) {
1750
- super(message);
1751
- this.name = "GencowValidationError";
1752
- }
1753
- };
1754
- var GENCOW_OPTIONAL_INNER = /* @__PURE__ */ Symbol.for("gencow.v.optionalInner");
1755
- function assertStandardResult(value) {
1756
- return { value };
1757
- }
1758
- function failStandardResult(message) {
1759
- return { issues: [{ message }] };
1760
- }
1761
- function readJsonSchemaFragment(validator) {
1762
- const opt = validator[GENCOW_OPTIONAL_INNER];
1763
- const target = opt ?? validator;
1764
- const raw = target["~standard"]?.jsonSchema;
1765
- if (raw === void 0) return {};
1766
- return typeof raw === "function" ? raw() : raw;
1767
- }
1768
- function matchesMimeType(fileType, pattern) {
1769
- const normalizedFileType = fileType.split(";")[0].trim().toLowerCase();
1770
- const normalizedPattern = pattern.trim().toLowerCase();
1771
- if (normalizedPattern === "*/*") return true;
1772
- if (normalizedPattern.endsWith("/*")) {
1773
- const prefix = normalizedPattern.slice(0, -1);
1774
- return normalizedFileType.startsWith(prefix);
1775
- }
1776
- return normalizedFileType === normalizedPattern;
1777
- }
1778
- function buildObjectJsonSchema(fields) {
1779
- const properties = {};
1780
- const required = [];
1781
- for (const key of Object.keys(fields)) {
1782
- const field = fields[key];
1783
- properties[key] = readJsonSchemaFragment(field);
1784
- if (!Object.prototype.hasOwnProperty.call(field, GENCOW_OPTIONAL_INNER)) {
1785
- required.push(key);
1786
- }
1787
- }
1788
- return {
1789
- type: "object",
1790
- properties,
1791
- ...required.length > 0 ? { required } : {}
1792
- };
1793
- }
1794
- function createValidator(config) {
1795
- const { parse, _type, jsonSchema } = config;
1796
- const standard = {
1797
- version: 1,
1798
- vendor: "gencow",
1799
- types: {},
1800
- validate: async (value) => {
1801
- try {
1802
- return assertStandardResult(parse(value));
1803
- } catch (e) {
1804
- const message = e instanceof Error ? e.message : "Validation failed";
1805
- return failStandardResult(message);
1806
- }
1807
- },
1808
- ...jsonSchema !== void 0 ? { jsonSchema } : {}
1809
- };
1810
- return {
1811
- parse,
1812
- _type,
1813
- "~standard": standard
1814
- };
1815
- }
1816
- var v = {
1817
- string() {
1818
- return createValidator({
1819
- parse: (val) => {
1820
- if (typeof val !== "string") throw new Error(`Expected string, got ${typeof val}`);
1821
- return val;
1822
- },
1823
- _type: "",
1824
- jsonSchema: { type: "string" }
1825
- });
1826
- },
1827
- number() {
1828
- return createValidator({
1829
- parse: (val) => {
1830
- const n = typeof val === "string" ? Number(val) : val;
1831
- if (typeof n !== "number" || isNaN(n)) throw new Error(`Expected number, got ${typeof val}`);
1832
- return n;
1833
- },
1834
- _type: 0,
1835
- jsonSchema: { type: "number" }
1836
- });
1837
- },
1838
- boolean() {
1839
- return createValidator({
1840
- parse: (val) => {
1841
- if (typeof val !== "boolean") throw new Error(`Expected boolean, got ${typeof val}`);
1842
- return val;
1843
- },
1844
- _type: false,
1845
- jsonSchema: { type: "boolean" }
1846
- });
1847
- },
1848
- /** ISO / `Date` — used for Drizzle `timestamp` columns; codegen maps to `Date`. */
1849
- dateTime() {
1850
- return createValidator({
1851
- parse: (val) => {
1852
- if (val instanceof Date && !Number.isNaN(val.getTime())) return val;
1853
- if (typeof val === "string") {
1854
- const d = new Date(val);
1855
- if (!Number.isNaN(d.getTime())) return d;
1856
- }
1857
- if (typeof val === "number" && Number.isFinite(val)) {
1858
- const d = new Date(val);
1859
- if (!Number.isNaN(d.getTime())) return d;
1860
- }
1861
- throw new Error(`Expected date, got ${typeof val}`);
1862
- },
1863
- _type: /* @__PURE__ */ new Date(0),
1864
- jsonSchema: { type: "string", format: "date-time" }
1865
- });
1866
- },
1867
- any() {
1868
- return createValidator({
1869
- parse: (val) => val,
1870
- _type: null
1871
- });
1872
- },
1873
- optional(inner) {
1874
- const out = createValidator({
1875
- parse: (val) => {
1876
- if (val === void 0 || val === null) return void 0;
1877
- return inner.parse(val);
1878
- },
1879
- _type: void 0,
1880
- jsonSchema: readJsonSchemaFragment(inner)
1881
- });
1882
- out[GENCOW_OPTIONAL_INNER] = inner;
1883
- return out;
1884
- },
1885
- nullable(inner) {
1886
- return createValidator({
1887
- parse: (val) => {
1888
- if (val === null) return null;
1889
- return inner.parse(val);
1890
- },
1891
- _type: null,
1892
- jsonSchema: { anyOf: [readJsonSchemaFragment(inner), { type: "null" }] }
1893
- });
1894
- },
1895
- object(fields) {
1896
- return createValidator({
1897
- parse: (val) => {
1898
- if (typeof val !== "object" || val === null) throw new Error("Expected object");
1899
- const result = {};
1900
- for (const key in fields) {
1901
- result[key] = fields[key].parse(val[key]);
1902
- }
1903
- return result;
1904
- },
1905
- _type: {},
1906
- jsonSchema: buildObjectJsonSchema(fields)
1907
- });
1908
- },
1909
- array(inner) {
1910
- const items = readJsonSchemaFragment(inner);
1911
- return createValidator({
1912
- parse: (val) => {
1913
- if (!Array.isArray(val)) throw new Error("Expected array");
1914
- return val.map((item) => inner.parse(item));
1915
- },
1916
- _type: [],
1917
- jsonSchema: { type: "array", items }
1918
- });
1919
- },
1920
- /** Browser `File` / `Blob` for procedure multipart uploads. */
1921
- file() {
1922
- const base = createValidator({
1923
- parse: (val) => {
1924
- if (!(val instanceof Blob)) {
1925
- throw new Error(`Expected file, got ${typeof val}`);
1926
- }
1927
- return val;
1928
- },
1929
- _type: null,
1930
- jsonSchema: { type: "string", format: "binary", "x-gencow-type": "file" }
1931
- });
1932
- return Object.assign(base, {
1933
- mime(mimeType) {
1934
- return createValidator({
1935
- parse: (val) => {
1936
- const blob = base.parse(val);
1937
- if (!matchesMimeType(blob.type, mimeType)) {
1938
- throw new Error(
1939
- `Expected a file of type ${mimeType} but got ${blob.type || "unknown"}`
1940
- );
1941
- }
1942
- return blob;
1943
- },
1944
- _type: null,
1945
- jsonSchema: {
1946
- type: "string",
1947
- format: "binary",
1948
- "x-gencow-type": "file",
1949
- "x-gencow-mime": mimeType
1950
- }
1951
- });
1952
- }
1953
- });
1954
- }
1955
- };
1956
- function parseArgs(schema, args) {
1957
- if (!schema) return args;
1958
- if (typeof schema.parse === "function") {
1959
- try {
1960
- return schema.parse(args);
1961
- } catch (e) {
1962
- throw new GencowValidationError(e.message);
1963
- }
1964
- }
1965
- if (typeof schema === "object" && schema !== null) {
1966
- const schemaKeys = Object.keys(schema);
1967
- if (schemaKeys.length === 0) return args;
1968
- if (typeof args !== "object" || args === null) {
1969
- throw new GencowValidationError("Expected an object for arguments");
1970
- }
1971
- const result = {};
1972
- for (const key of schemaKeys) {
1973
- const validator = schema[key];
1974
- if (validator && typeof validator.parse === "function") {
1975
- try {
1976
- result[key] = validator.parse(args[key]);
1977
- } catch (e) {
1978
- throw new GencowValidationError(`Argument "${key}": ${e.message}`);
1979
- }
1980
- } else {
1981
- result[key] = args[key];
1982
- }
1983
- }
1984
- return result;
1985
- }
1986
- return args;
1987
- }
1988
-
1989
2019
  // ../core/src/workflow-types.ts
1990
2020
  function deriveWorkflowStatus(status, currentStep) {
1991
2021
  if (status !== "pending") {
@@ -2774,6 +2804,8 @@ var RESERVED_TENANT_RUNTIME_ENV_KEYS = /* @__PURE__ */ new Set([
2774
2804
  "GENCOW_FUNCTIONS",
2775
2805
  "GENCOW_STORAGE",
2776
2806
  "GENCOW_STORAGE_REQUIRE_READ_GRANT",
2807
+ "GENCOW_STORAGE_BACKEND",
2808
+ "GENCOW_STORAGE_LEGACY_LOCAL_FALLBACK",
2777
2809
  "GENCOW_MIGRATIONS",
2778
2810
  "GENCOW_APP_NAME",
2779
2811
  "GENCOW_APP_DATA_DIR",
@@ -2799,6 +2831,7 @@ var RESERVED_TENANT_RUNTIME_ENV_KEYS = /* @__PURE__ */ new Set([
2799
2831
  ]);
2800
2832
  var RESERVED_TENANT_RUNTIME_ENV_PREFIXES = [
2801
2833
  "__GENCOW_",
2834
+ "GENCOW_PLATFORM_STORAGE_",
2802
2835
  "GENCOW_DOCUMENT_",
2803
2836
  "GENCOW_TEMPLATE_",
2804
2837
  "GENCOW_WARM_"