@fragno-dev/create 0.1.4 → 0.1.5

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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @fragno-dev/create@0.1.4 build /home/runner/work/fragno/fragno/packages/create
2
+ > @fragno-dev/create@0.1.5 build /home/runner/work/fragno/fragno/packages/create
3
3
  > tsdown
4
4
 
5
5
  ℹ tsdown v0.15.12 powered by rolldown v1.0.0-beta.45
@@ -12,4 +12,4 @@
12
12
  ℹ dist/index.d.ts.map  0.58 kB │ gzip: 0.31 kB
13
13
  ℹ dist/index.d.ts  1.28 kB │ gzip: 0.48 kB
14
14
  ℹ 4 files, total: 19.08 kB
15
- ✔ Build complete in 3797ms
15
+ ✔ Build complete in 1641ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @fragno-dev/create
2
2
 
3
+ ## 0.1.5
4
+
5
+ ### Patch Changes
6
+
7
+ - 68135c4: Update database template to use latest fragno-db UOW API and bump dependency versions in
8
+ generated fragments
9
+
3
10
  ## 0.1.4
4
11
 
5
12
  ### Patch Changes
package/dist/index.js CHANGED
@@ -47,10 +47,10 @@ function copy(from, to, rename = identity) {
47
47
 
48
48
  //#endregion
49
49
  //#region src/package-json.ts
50
- const fragnoCoreVersion = "0.1.10";
51
- const fragnoDbVersion = "0.1.15";
50
+ const fragnoCoreVersion = "0.1.11";
51
+ const fragnoDbVersion = "0.2.0";
52
52
  const unpluginFragnoVersion = "0.0.7";
53
- const fragnoCliVersion = "0.1.20";
53
+ const fragnoCliVersion = "0.1.21";
54
54
  const basePkg = {
55
55
  dependencies: {
56
56
  "@fragno-dev/core": fragnoCoreVersion,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["e: unknown","basePkg: Record<string, unknown>","databasePkg: Record<string, unknown>","buildToolPkg: Record<BuildTools, Record<string, unknown>>","pkgOverride: Record<string, unknown>"],"sources":["../src/utils.ts","../src/package-json.ts","../src/index.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\n\nexport function mkdirp(dir: string): void {\n try {\n fs.mkdirSync(dir, { recursive: true });\n } catch (e: unknown) {\n if (e instanceof Error && \"code\" in e && e.code === \"EEXIST\") {\n return;\n }\n throw e;\n }\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return (\n value !== null &&\n typeof value === \"object\" &&\n !Array.isArray(value) &&\n Object.prototype.toString.call(value) === \"[object Object]\"\n );\n}\n\n/**\n * Deep merge plain objects. Arrays and primitives are overwritten, not merged.\n * @param target The target object\n * @param source The source object\n * @returns The merged object\n */\nexport function merge<T extends Record<string, unknown>>(\n target: T,\n source: Record<string, unknown>,\n): T {\n const result = { ...target } as Record<string, unknown>;\n\n for (const key in source) {\n const sourceValue = source[key];\n const targetValue = result[key];\n\n if (isPlainObject(sourceValue) && isPlainObject(targetValue)) {\n result[key] = merge(targetValue, sourceValue);\n } else {\n result[key] = sourceValue;\n }\n }\n\n return result as T;\n}\n\nfunction identity<T>(x: T): T {\n return x;\n}\n\nexport function copy(\n from: string,\n to: string,\n rename: (basename: string) => string = identity,\n): void {\n if (!fs.existsSync(from)) {\n return;\n }\n\n const stats = fs.statSync(from);\n\n if (stats.isDirectory()) {\n fs.readdirSync(from).forEach((file) => {\n copy(path.join(from, file), path.join(to, rename(file)));\n });\n } else {\n mkdirp(path.dirname(to));\n fs.copyFileSync(from, to);\n }\n}\n","import type { BuildTools } from \"./index\";\n\nconst fragnoCoreVersion = \"0.1.10\";\nconst fragnoDbVersion = \"0.1.15\";\nconst unpluginFragnoVersion = \"0.0.7\";\nconst fragnoCliVersion = \"0.1.20\";\n\nexport const basePkg: Record<string, unknown> = {\n dependencies: {\n \"@fragno-dev/core\": fragnoCoreVersion,\n \"@standard-schema/spec\": \"^1.0.0\",\n zod: \"^4.0.5\",\n },\n devDependencies: {\n \"@types/node\": \"^24\",\n \"@fragno-dev/cli\": fragnoCliVersion,\n \"@fragno-dev/unplugin-fragno\": unpluginFragnoVersion,\n },\n peerDependencies: {\n typescript: \">=5\",\n react: \">=18.0.0\",\n svelte: \">=4.0.0\",\n \"solid-js\": \">=1.0.0\",\n vue: \">=3.0.0\",\n },\n};\n\nexport const databasePkg: Record<string, unknown> = {\n devDependencies: {\n \"@fragno-dev/db\": fragnoDbVersion,\n },\n peerDependencies: {\n \"@fragno-dev/db\": fragnoDbVersion,\n },\n};\n\nexport const buildToolPkg: Record<BuildTools, Record<string, unknown>> = {\n none: {},\n tsdown: {\n devDependencies: {\n tsdown: \"^0.12.0\",\n },\n scripts: {\n build: \"tsdown\",\n },\n },\n esbuild: {\n devDependencies: {\n esbuild: \"^0.25.12\",\n },\n scripts: {\n build: \"./esbuild.config.js\",\n },\n },\n vite: {\n devDependencies: {\n vite: \"^6.3.5\",\n },\n scripts: {\n build: \"vite build\",\n },\n },\n rollup: {\n devDependencies: {\n \"@rollup/plugin-node-resolve\": \"^16.0.2\",\n \"@rollup/plugin-typescript\": \"^12.1.4\",\n tslib: \"^2.8.1\",\n rollup: \"^4.41.0\",\n },\n scripts: {\n build: \"rollup -c\",\n },\n },\n webpack: {\n devDependencies: {\n webpack: \"^5.99.9\",\n \"webpack-cli\": \"^6.0.1\",\n \"ts-loader\": \"^9.5.1\",\n },\n scripts: {\n build: \"webpack\",\n },\n },\n rspack: {\n devDependencies: {\n \"@rspack/core\": \"^1.6.1\",\n \"@rspack/cli\": \"^1.6.1\",\n },\n scripts: {\n build: \"rspack build\",\n },\n },\n};\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { copy, merge } from \"./utils.ts\";\nimport { basePkg, buildToolPkg, databasePkg } from \"./package-json.ts\";\nimport { z } from \"zod\";\n\nconst templateTypesSchema = z.literal(\"fragment\");\nexport type TemplateTypes = z.infer<typeof templateTypesSchema>;\n\nconst buildToolsSchema = z.enum([\n \"esbuild\",\n \"tsdown\",\n \"vite\",\n \"rollup\",\n \"webpack\",\n \"rspack\",\n \"none\",\n]);\nexport type BuildTools = z.infer<typeof buildToolsSchema>;\n\nconst agentDocsSchema = z.enum([\"AGENTS.md\", \"CLAUDE.md\", \"none\"]);\nexport type AgentDocs = z.infer<typeof agentDocsSchema>;\n\nexport const createOptionsSchema = z.object({\n path: z.string(),\n buildTool: buildToolsSchema,\n name: z.string(),\n template: templateTypesSchema,\n agentDocs: agentDocsSchema,\n withDatabase: z.boolean(),\n});\n\ntype CreateOptions = z.infer<typeof createOptionsSchema>;\n\nexport function create(options: CreateOptions) {\n let pkgOverride: Record<string, unknown> = merge(basePkg, { name: options.name });\n\n // Build tool pkg overrides\n pkgOverride = merge(pkgOverride, buildToolPkg[options.buildTool]);\n\n // Database pkg overrides\n if (options.withDatabase) {\n pkgOverride = merge(pkgOverride, databasePkg);\n }\n\n if (options.template == \"fragment\") {\n writeFragmentTemplate(options.path, pkgOverride);\n } else {\n throw new Error(`Unsupported template type: ${options.template}`);\n }\n\n switch (options.buildTool) {\n case \"esbuild\":\n writeOptionalTemplate(options.path, \"builder/esbuild.config.js\");\n break;\n case \"tsdown\":\n writeOptionalTemplate(options.path, \"builder/tsdown.config.ts\");\n break;\n case \"vite\":\n writeOptionalTemplate(options.path, \"builder/vite.config.ts\");\n break;\n case \"rollup\":\n writeOptionalTemplate(options.path, \"builder/rollup.config.js\");\n break;\n case \"webpack\":\n writeOptionalTemplate(options.path, \"builder/webpack.config.js\");\n break;\n case \"rspack\":\n writeOptionalTemplate(options.path, \"builder/rspack.config.js\");\n break;\n case \"none\":\n break;\n }\n\n switch (options.agentDocs) {\n case \"AGENTS.md\":\n writeOptionalTemplate(options.path, \"agent/AGENTS.md\");\n break;\n case \"CLAUDE.md\":\n writeOptionalTemplate(options.path, \"agent/AGENTS.md\", \"CLAUDE.md\");\n break;\n case \"none\":\n break;\n }\n\n if (options.withDatabase) {\n writeOptionalTemplate(options.path, \"database/index.ts\", \"src/index.ts\");\n writeOptionalTemplate(options.path, \"database/schema.ts\", \"src/schema.ts\");\n }\n}\n\nfunction getTemplateDir(): string {\n const __dirname = path.dirname(fileURLToPath(import.meta.url));\n return path.join(__dirname, \"..\", \"templates\");\n}\n\nfunction writeOptionalTemplate(targetPath: string, template: string, rename?: string) {\n const templatePath = path.join(getTemplateDir(), \"optional\", template);\n const targetFileName = rename ? rename : path.basename(template);\n const targetFile = path.join(targetPath, targetFileName);\n\n copy(templatePath, targetFile);\n}\n\nfunction writeFragmentTemplate(targetPath: string, pkgOverrides: Record<string, unknown>) {\n const templateDir = path.join(getTemplateDir(), \"fragment\");\n\n // Copy template files\n copy(templateDir, targetPath, (basename) => {\n if (basename === \"package.template.json\") {\n return \"package.json\";\n }\n return basename;\n });\n\n // Update package.json based on chosen options\n const packageJsonPath = path.join(targetPath, \"package.json\");\n const basePkg = JSON.parse(fs.readFileSync(packageJsonPath, \"utf-8\"));\n const newPkg = merge(basePkg, pkgOverrides);\n\n // Write to disk\n fs.writeFileSync(packageJsonPath, JSON.stringify(newPkg, null, 2) + \"\\n\");\n}\n"],"mappings":";;;;;;AAGA,SAAgB,OAAO,KAAmB;AACxC,KAAI;AACF,KAAG,UAAU,KAAK,EAAE,WAAW,MAAM,CAAC;UAC/BA,GAAY;AACnB,MAAI,aAAa,SAAS,UAAU,KAAK,EAAE,SAAS,SAClD;AAEF,QAAM;;;AAIV,SAAS,cAAc,OAAkD;AACvE,QACE,UAAU,QACV,OAAO,UAAU,YACjB,CAAC,MAAM,QAAQ,MAAM,IACrB,OAAO,UAAU,SAAS,KAAK,MAAM,KAAK;;;;;;;;AAU9C,SAAgB,MACd,QACA,QACG;CACH,MAAM,SAAS,EAAE,GAAG,QAAQ;AAE5B,MAAK,MAAM,OAAO,QAAQ;EACxB,MAAM,cAAc,OAAO;EAC3B,MAAM,cAAc,OAAO;AAE3B,MAAI,cAAc,YAAY,IAAI,cAAc,YAAY,CAC1D,QAAO,OAAO,MAAM,aAAa,YAAY;MAE7C,QAAO,OAAO;;AAIlB,Q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AACnE;EACF,KAAK,OACH;;AAGJ,KAAI,QAAQ,cAAc;AACxB,wBAAsB,QAAQ,MAAM,qBAAqB,eAAe;AACxE,wBAAsB,QAAQ,MAAM,sBAAsB,gBAAgB;;;AAI9E,SAAS,iBAAyB;CAChC,MAAM,YAAY,KAAK,QAAQ,cAAc,OAAO,KAAK,IAAI,CAAC;AAC9D,QAAO,KAAK,KAAK,WAAW,MAAM,YAAY;;AAGhD,SAAS,sBAAsB,YAAoB,UAAkB,QAAiB;CACpF,MAAM,eAAe,KAAK,KAAK,gBAAgB,EAAE,YAAY,SAAS;CACtE,MAAM,iBAAiB,SAAS,SAAS,KAAK,SAAS,SAAS;AAGhE,MAAK,cAFc,KAAK,KAAK,YAAY,eAAe,CAE1B;;AAGhC,SAAS,sBAAsB,YAAoB,cAAuC;AAIxF,MAHoB,KAAK,KAAK,gBAAgB,EAAE,WAAW,EAGzC,aAAa,aAAa;AAC1C,MAAI,aAAa,wBACf,QAAO;AAET,SAAO;GACP;CAGF,MAAM,kBAAkB,KAAK,KAAK,YAAY,eAAe;CAE7D,MAAM,SAAS,MADC,KAAK,MAAM,GAAG,aAAa,iBAAiB,QAAQ,CAAC,EACvC,aAAa;AAG3C,IAAG,cAAc,iBAAiB,KAAK,UAAU,QAAQ,MAAM,EAAE,GAAG,KAAK"}
1
+ {"version":3,"file":"index.js","names":["e: unknown","basePkg: Record<string, unknown>","databasePkg: Record<string, unknown>","buildToolPkg: Record<BuildTools, Record<string, unknown>>","pkgOverride: Record<string, unknown>"],"sources":["../src/utils.ts","../src/package-json.ts","../src/index.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\n\nexport function mkdirp(dir: string): void {\n try {\n fs.mkdirSync(dir, { recursive: true });\n } catch (e: unknown) {\n if (e instanceof Error && \"code\" in e && e.code === \"EEXIST\") {\n return;\n }\n throw e;\n }\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return (\n value !== null &&\n typeof value === \"object\" &&\n !Array.isArray(value) &&\n Object.prototype.toString.call(value) === \"[object Object]\"\n );\n}\n\n/**\n * Deep merge plain objects. Arrays and primitives are overwritten, not merged.\n * @param target The target object\n * @param source The source object\n * @returns The merged object\n */\nexport function merge<T extends Record<string, unknown>>(\n target: T,\n source: Record<string, unknown>,\n): T {\n const result = { ...target } as Record<string, unknown>;\n\n for (const key in source) {\n const sourceValue = source[key];\n const targetValue = result[key];\n\n if (isPlainObject(sourceValue) && isPlainObject(targetValue)) {\n result[key] = merge(targetValue, sourceValue);\n } else {\n result[key] = sourceValue;\n }\n }\n\n return result as T;\n}\n\nfunction identity<T>(x: T): T {\n return x;\n}\n\nexport function copy(\n from: string,\n to: string,\n rename: (basename: string) => string = identity,\n): void {\n if (!fs.existsSync(from)) {\n return;\n }\n\n const stats = fs.statSync(from);\n\n if (stats.isDirectory()) {\n fs.readdirSync(from).forEach((file) => {\n copy(path.join(from, file), path.join(to, rename(file)));\n });\n } else {\n mkdirp(path.dirname(to));\n fs.copyFileSync(from, to);\n }\n}\n","import type { BuildTools } from \"./index\";\n\nconst fragnoCoreVersion = \"0.1.11\";\nconst fragnoDbVersion = \"0.2.0\";\nconst unpluginFragnoVersion = \"0.0.7\";\nconst fragnoCliVersion = \"0.1.21\";\n\nexport const basePkg: Record<string, unknown> = {\n dependencies: {\n \"@fragno-dev/core\": fragnoCoreVersion,\n \"@standard-schema/spec\": \"^1.0.0\",\n zod: \"^4.0.5\",\n },\n devDependencies: {\n \"@types/node\": \"^24\",\n \"@fragno-dev/cli\": fragnoCliVersion,\n \"@fragno-dev/unplugin-fragno\": unpluginFragnoVersion,\n },\n peerDependencies: {\n typescript: \">=5\",\n react: \">=18.0.0\",\n svelte: \">=4.0.0\",\n \"solid-js\": \">=1.0.0\",\n vue: \">=3.0.0\",\n },\n};\n\nexport const databasePkg: Record<string, unknown> = {\n devDependencies: {\n \"@fragno-dev/db\": fragnoDbVersion,\n },\n peerDependencies: {\n \"@fragno-dev/db\": fragnoDbVersion,\n },\n};\n\nexport const buildToolPkg: Record<BuildTools, Record<string, unknown>> = {\n none: {},\n tsdown: {\n devDependencies: {\n tsdown: \"^0.12.0\",\n },\n scripts: {\n build: \"tsdown\",\n },\n },\n esbuild: {\n devDependencies: {\n esbuild: \"^0.25.12\",\n },\n scripts: {\n build: \"./esbuild.config.js\",\n },\n },\n vite: {\n devDependencies: {\n vite: \"^6.3.5\",\n },\n scripts: {\n build: \"vite build\",\n },\n },\n rollup: {\n devDependencies: {\n \"@rollup/plugin-node-resolve\": \"^16.0.2\",\n \"@rollup/plugin-typescript\": \"^12.1.4\",\n tslib: \"^2.8.1\",\n rollup: \"^4.41.0\",\n },\n scripts: {\n build: \"rollup -c\",\n },\n },\n webpack: {\n devDependencies: {\n webpack: \"^5.99.9\",\n \"webpack-cli\": \"^6.0.1\",\n \"ts-loader\": \"^9.5.1\",\n },\n scripts: {\n build: \"webpack\",\n },\n },\n rspack: {\n devDependencies: {\n \"@rspack/core\": \"^1.6.1\",\n \"@rspack/cli\": \"^1.6.1\",\n },\n scripts: {\n build: \"rspack build\",\n },\n },\n};\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { copy, merge } from \"./utils.ts\";\nimport { basePkg, buildToolPkg, databasePkg } from \"./package-json.ts\";\nimport { z } from \"zod\";\n\nconst templateTypesSchema = z.literal(\"fragment\");\nexport type TemplateTypes = z.infer<typeof templateTypesSchema>;\n\nconst buildToolsSchema = z.enum([\n \"esbuild\",\n \"tsdown\",\n \"vite\",\n \"rollup\",\n \"webpack\",\n \"rspack\",\n \"none\",\n]);\nexport type BuildTools = z.infer<typeof buildToolsSchema>;\n\nconst agentDocsSchema = z.enum([\"AGENTS.md\", \"CLAUDE.md\", \"none\"]);\nexport type AgentDocs = z.infer<typeof agentDocsSchema>;\n\nexport const createOptionsSchema = z.object({\n path: z.string(),\n buildTool: buildToolsSchema,\n name: z.string(),\n template: templateTypesSchema,\n agentDocs: agentDocsSchema,\n withDatabase: z.boolean(),\n});\n\ntype CreateOptions = z.infer<typeof createOptionsSchema>;\n\nexport function create(options: CreateOptions) {\n let pkgOverride: Record<string, unknown> = merge(basePkg, { name: options.name });\n\n // Build tool pkg overrides\n pkgOverride = merge(pkgOverride, buildToolPkg[options.buildTool]);\n\n // Database pkg overrides\n if (options.withDatabase) {\n pkgOverride = merge(pkgOverride, databasePkg);\n }\n\n if (options.template == \"fragment\") {\n writeFragmentTemplate(options.path, pkgOverride);\n } else {\n throw new Error(`Unsupported template type: ${options.template}`);\n }\n\n switch (options.buildTool) {\n case \"esbuild\":\n writeOptionalTemplate(options.path, \"builder/esbuild.config.js\");\n break;\n case \"tsdown\":\n writeOptionalTemplate(options.path, \"builder/tsdown.config.ts\");\n break;\n case \"vite\":\n writeOptionalTemplate(options.path, \"builder/vite.config.ts\");\n break;\n case \"rollup\":\n writeOptionalTemplate(options.path, \"builder/rollup.config.js\");\n break;\n case \"webpack\":\n writeOptionalTemplate(options.path, \"builder/webpack.config.js\");\n break;\n case \"rspack\":\n writeOptionalTemplate(options.path, \"builder/rspack.config.js\");\n break;\n case \"none\":\n break;\n }\n\n switch (options.agentDocs) {\n case \"AGENTS.md\":\n writeOptionalTemplate(options.path, \"agent/AGENTS.md\");\n break;\n case \"CLAUDE.md\":\n writeOptionalTemplate(options.path, \"agent/AGENTS.md\", \"CLAUDE.md\");\n break;\n case \"none\":\n break;\n }\n\n if (options.withDatabase) {\n writeOptionalTemplate(options.path, \"database/index.ts\", \"src/index.ts\");\n writeOptionalTemplate(options.path, \"database/schema.ts\", \"src/schema.ts\");\n }\n}\n\nfunction getTemplateDir(): string {\n const __dirname = path.dirname(fileURLToPath(import.meta.url));\n return path.join(__dirname, \"..\", \"templates\");\n}\n\nfunction writeOptionalTemplate(targetPath: string, template: string, rename?: string) {\n const templatePath = path.join(getTemplateDir(), \"optional\", template);\n const targetFileName = rename ? rename : path.basename(template);\n const targetFile = path.join(targetPath, targetFileName);\n\n copy(templatePath, targetFile);\n}\n\nfunction writeFragmentTemplate(targetPath: string, pkgOverrides: Record<string, unknown>) {\n const templateDir = path.join(getTemplateDir(), \"fragment\");\n\n // Copy template files\n copy(templateDir, targetPath, (basename) => {\n if (basename === \"package.template.json\") {\n return \"package.json\";\n }\n return basename;\n });\n\n // Update package.json based on chosen options\n const packageJsonPath = path.join(targetPath, \"package.json\");\n const basePkg = JSON.parse(fs.readFileSync(packageJsonPath, \"utf-8\"));\n const newPkg = merge(basePkg, pkgOverrides);\n\n // Write to disk\n fs.writeFileSync(packageJsonPath, JSON.stringify(newPkg, null, 2) + \"\\n\");\n}\n"],"mappings":";;;;;;AAGA,SAAgB,OAAO,KAAmB;AACxC,KAAI;AACF,KAAG,UAAU,KAAK,EAAE,WAAW,MAAM,CAAC;UAC/BA,GAAY;AACnB,MAAI,aAAa,SAAS,UAAU,KAAK,EAAE,SAAS,SAClD;AAEF,QAAM;;;AAIV,SAAS,cAAc,OAAkD;AACvE,QACE,UAAU,QACV,OAAO,UAAU,YACjB,CAAC,MAAM,QAAQ,MAAM,IACrB,OAAO,UAAU,SAAS,KAAK,MAAM,KAAK;;;;;;;;AAU9C,SAAgB,MACd,QACA,QACG;CACH,MAAM,SAAS,EAAE,GAAG,QAAQ;AAE5B,MAAK,MAAM,OAAO,QAAQ;EACxB,MAAM,cAAc,OAAO;EAC3B,MAAM,cAAc,OAAO;AAE3B,MAAI,cAAc,YAAY,IAAI,cAAc,YAAY,CAC1D,QAAO,OAAO,MAAM,aAAa,YAAY;MAE7C,QAAO,OAAO;;AAIlB,QAAO;;AAGT,SAAS,SAAY,GAAS;AAC5B,QAAO;;AAGT,SAAgB,KACd,MACA,IACA,SAAuC,UACjC;AACN,KAAI,CAAC,GAAG,WAAW,KAAK,CACtB;AAKF,KAFc,GAAG,SAAS,KAAK,CAErB,aAAa,CACrB,IAAG,YAAY,KAAK,CAAC,SAAS,SAAS;AACrC,OAAK,KAAK,KAAK,MAAM,KAAK,EAAE,KAAK,KAAK,IAAI,OAAO,KA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sBAAsB,YAAoB,UAAkB,QAAiB;CACpF,MAAM,eAAe,KAAK,KAAK,gBAAgB,EAAE,YAAY,SAAS;CACtE,MAAM,iBAAiB,SAAS,SAAS,KAAK,SAAS,SAAS;AAGhE,MAAK,cAFc,KAAK,KAAK,YAAY,eAAe,CAE1B;;AAGhC,SAAS,sBAAsB,YAAoB,cAAuC;AAIxF,MAHoB,KAAK,KAAK,gBAAgB,EAAE,WAAW,EAGzC,aAAa,aAAa;AAC1C,MAAI,aAAa,wBACf,QAAO;AAET,SAAO;GACP;CAGF,MAAM,kBAAkB,KAAK,KAAK,YAAY,eAAe;CAE7D,MAAM,SAAS,MADC,KAAK,MAAM,GAAG,aAAa,iBAAiB,QAAQ,CAAC,EACvC,aAAa;AAG3C,IAAG,cAAc,iBAAiB,KAAK,UAAU,QAAQ,MAAM,EAAE,GAAG,KAAK"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fragno-dev/create",
3
3
  "description": "A library for creating Fragno fragments",
4
- "version": "0.1.4",
4
+ "version": "0.1.5",
5
5
  "exports": {
6
6
  ".": {
7
7
  "development": "./src/index.ts",
@@ -62,13 +62,25 @@ function createFragmentTestSuite(buildTool: BuildTool, withDatabase: boolean) {
62
62
  expect(stdout).toBeDefined();
63
63
  });
64
64
 
65
- test("compiles", { timeout: 30000 }, async () => {
66
- const { stdout } = await execAsync("pnpm run types:check", {
67
- cwd: tempDir,
68
- encoding: "utf8",
69
- });
70
- console.log(stdout);
71
- expect(stdout).toBeDefined();
65
+ test("type checks (compiles)", { timeout: 30000 }, async () => {
66
+ try {
67
+ const { stdout } = await execAsync("pnpm run types:check", {
68
+ cwd: tempDir,
69
+ encoding: "utf8",
70
+ });
71
+ expect(stdout).toBeDefined();
72
+ } catch (error: unknown) {
73
+ // When command fails, stdout and stderr are in the error object
74
+ const execError = error as { stdout?: string; stderr?: string };
75
+ console.error("TypeScript type check failed:");
76
+ if (execError.stdout) {
77
+ console.error(execError.stdout);
78
+ }
79
+ if (execError.stderr) {
80
+ console.error(execError.stderr);
81
+ }
82
+ throw error;
83
+ }
72
84
  });
73
85
  /*
74
86
  FIXME: Skipping this test for rollup:
@@ -1,9 +1,9 @@
1
1
  import type { BuildTools } from "./index";
2
2
 
3
- const fragnoCoreVersion = "0.1.10";
4
- const fragnoDbVersion = "0.1.15";
3
+ const fragnoCoreVersion = "0.1.11";
4
+ const fragnoDbVersion = "0.2.0";
5
5
  const unpluginFragnoVersion = "0.0.7";
6
- const fragnoCliVersion = "0.1.20";
6
+ const fragnoCliVersion = "0.1.21";
7
7
 
8
8
  export const basePkg: Record<string, unknown> = {
9
9
  dependencies: {
@@ -1,6 +1,10 @@
1
1
  import { defineFragment, defineRoutes, instantiate } from "@fragno-dev/core";
2
2
  import { createClientBuilder, type FragnoPublicClientConfig } from "@fragno-dev/core/client";
3
- import { withDatabase, type FragnoPublicConfigWithDatabase } from "@fragno-dev/db";
3
+ import {
4
+ withDatabase,
5
+ type FragnoPublicConfigWithDatabase,
6
+ ExponentialBackoffRetryPolicy,
7
+ } from "@fragno-dev/db";
4
8
  import type { TableToInsertValues } from "@fragno-dev/db/query";
5
9
  import { noteSchema } from "./schema";
6
10
 
@@ -11,29 +15,120 @@ import { z } from "zod";
11
15
 
12
16
  export interface ExampleConfig {
13
17
  // Add any server-side configuration here if needed
18
+ onNoteCreated?: (nonce: string, payload: { noteId: string; userId: string }) => Promise<void>;
14
19
  }
15
20
 
16
21
  const exampleFragmentDefinition = defineFragment<ExampleConfig>("example-fragment")
17
22
  .extend(withDatabase(noteSchema))
18
- .providesBaseService(({ deps }) => {
19
- return {
20
- createNote: async (note: TableToInsertValues<typeof noteSchema.tables.note>) => {
21
- const id = await deps.db.create("note", note);
23
+ .provideHooks(({ defineHook, config }) => ({
24
+ onNoteCreated: defineHook(async function (payload: { noteId: string; userId: string }) {
25
+ // Hook runs after transaction commits, with retries on failure
26
+ // Use this.nonce for idempotency (available via this context)
27
+ await config.onNoteCreated?.(this.nonce, payload);
28
+ }),
29
+ }))
30
+ .providesBaseService(({ defineService }) => {
31
+ return defineService({
32
+ createNote: async function (
33
+ note: Omit<TableToInsertValues<typeof noteSchema.tables.note>, "userId"> & {
34
+ userId: string;
35
+ },
36
+ ) {
37
+ const uow = this.uow(noteSchema);
38
+
39
+ // Find user first to get FragnoId for reference
40
+ const userUow = uow.findFirst("user", (b) =>
41
+ b.whereIndex("idx_user_email", (eb) => eb("email", "=", note.userId)),
42
+ );
43
+ const [user] = await userUow.retrievalPhase;
44
+
45
+ if (!user) {
46
+ throw new Error("User not found");
47
+ }
48
+
49
+ // Create note with reference to user
50
+ const noteId = uow.create("note", {
51
+ content: note.content,
52
+ userId: user.id,
53
+ });
54
+
55
+ // Trigger durable hook (recorded in transaction, executed after commit)
56
+ uow.triggerHook("onNoteCreated", {
57
+ noteId: noteId.valueOf(),
58
+ userId: user.id.valueOf(),
59
+ });
60
+
61
+ // Wait for handler to execute mutation phase
62
+ await uow.mutationPhase;
63
+
22
64
  return {
23
- ...note,
24
- id: id.valueOf(),
25
- createdAt: note.createdAt ?? new Date(),
65
+ id: noteId.valueOf(),
66
+ content: note.content,
67
+ userId: user.id.valueOf(),
68
+ createdAt: new Date(),
26
69
  };
27
70
  },
28
- getNotes: () => {
29
- return deps.db.find("note", (b) => b);
71
+ getNotes: async function () {
72
+ const uow = this.uow(noteSchema).find("note", (b) =>
73
+ b.whereIndex("primary").join((j) => j.author()),
74
+ );
75
+ const [notes] = await uow.retrievalPhase;
76
+ return notes;
77
+ },
78
+ getNotesByUser: async function (userEmail: string) {
79
+ const uow = this.uow(noteSchema);
80
+
81
+ // First find the user by email
82
+ const userUow = uow.findFirst("user", (b) =>
83
+ b.whereIndex("idx_user_email", (eb) => eb("email", "=", userEmail)),
84
+ );
85
+ const [user] = await userUow.retrievalPhase;
86
+
87
+ if (!user) {
88
+ return [];
89
+ }
90
+
91
+ // Then find notes by the user's FragnoId
92
+ // Note: userId is a reference column, FragnoId works directly in whereIndex
93
+ const notesUow = uow.find("note", (b) =>
94
+ b.whereIndex("idx_note_user", (eb) => eb("userId", "=", user.id)).join((j) => j.author()),
95
+ );
96
+ const [notes] = await notesUow.retrievalPhase;
97
+ return notes;
30
98
  },
31
- getNotesByUser: (userId: string) => {
32
- return deps.db.find("note", (b) =>
33
- b.whereIndex("idx_note_user", (eb) => eb("userId", "=", userId)),
99
+ updateNote: async function (noteId: string, content: string) {
100
+ const uow = this.uow(noteSchema);
101
+
102
+ // Find note first to get FragnoId for optimistic concurrency control
103
+ // Join with author to get user information
104
+ const noteUow = uow.findFirst("note", (b) =>
105
+ b.whereIndex("primary", (eb) => eb("id", "=", noteId)).join((j) => j.author()),
34
106
  );
107
+ const [note] = await noteUow.retrievalPhase;
108
+
109
+ if (!note) {
110
+ throw new Error("Note not found");
111
+ }
112
+
113
+ // Update with optimistic concurrency control (.check())
114
+ uow.update("note", note.id, (b) => b.set({ content }).check());
115
+
116
+ // Wait for handler to execute mutation phase
117
+ // On optimistic conflict, handler will retry the whole transaction
118
+ await uow.mutationPhase;
119
+
120
+ if (!note.author) {
121
+ throw new Error("Note author not found");
122
+ }
123
+
124
+ return {
125
+ id: note.id.valueOf(),
126
+ content,
127
+ userId: note.author.id.valueOf(),
128
+ createdAt: note.createdAt,
129
+ };
35
130
  },
36
- };
131
+ });
37
132
  })
38
133
  .build();
39
134
 
@@ -49,32 +144,36 @@ const exampleRoutesFactory = defineRoutes(exampleFragmentDefinition).create(
49
144
  id: z.string(),
50
145
  content: z.string(),
51
146
  userId: z.string(),
147
+ userName: z.string(),
52
148
  createdAt: z.date(),
53
149
  }),
54
150
  ),
55
- handler: async ({ query }, { json }) => {
56
- const userId = query.get("userId");
151
+ handler: async function ({ query }, { json }) {
152
+ const userEmail = query.get("userId"); // Using userId param name for backward compatibility
153
+
154
+ const result = await this.uow(async ({ executeRetrieve }) => {
155
+ const notesPromise = userEmail
156
+ ? services.getNotesByUser(userEmail)
157
+ : services.getNotes();
158
+
159
+ // Execute all reads scheduled by services
160
+ await executeRetrieve();
161
+
162
+ return notesPromise;
163
+ });
57
164
 
58
- if (userId) {
59
- const notes = await services.getNotesByUser(userId);
60
- return json(
61
- notes.map((note) => ({
165
+ const notes = await result;
166
+
167
+ return json(
168
+ notes
169
+ .filter((note) => note.author !== null)
170
+ .map((note) => ({
62
171
  id: note.id.valueOf(),
63
172
  content: note.content,
64
- userId: note.userId,
173
+ userId: note.author!.id.valueOf(),
174
+ userName: note.author!.name,
65
175
  createdAt: note.createdAt,
66
176
  })),
67
- );
68
- }
69
-
70
- const notes = await services.getNotes();
71
- return json(
72
- notes.map((note) => ({
73
- id: note.id.valueOf(),
74
- content: note.content,
75
- userId: note.userId,
76
- createdAt: note.createdAt,
77
- })),
78
177
  );
79
178
  },
80
179
  }),
@@ -82,7 +181,7 @@ const exampleRoutesFactory = defineRoutes(exampleFragmentDefinition).create(
82
181
  defineRoute({
83
182
  method: "POST",
84
183
  path: "/notes",
85
- inputSchema: z.object({ content: z.string(), userId: z.string() }),
184
+ inputSchema: z.object({ content: z.string(), userEmail: z.string() }),
86
185
  outputSchema: z.object({
87
186
  id: z.string(),
88
187
  content: z.string(),
@@ -90,10 +189,71 @@ const exampleRoutesFactory = defineRoutes(exampleFragmentDefinition).create(
90
189
  createdAt: z.date(),
91
190
  }),
92
191
  errorCodes: [],
93
- handler: async ({ input }, { json }) => {
94
- const { content, userId } = await input.valid();
192
+ handler: async function ({ input }, { json }) {
193
+ const { content, userEmail } = await input.valid();
194
+
195
+ // Handler controls transaction execution with retry policy
196
+ const result = await this.uow(
197
+ async ({ executeMutate }) => {
198
+ const notePromise = services.createNote({ content, userId: userEmail });
199
+
200
+ // Execute retrieval (if needed) and mutation atomically
201
+ // On optimistic conflict, this whole callback retries
202
+ await executeMutate();
203
+
204
+ return notePromise;
205
+ },
206
+ {
207
+ // Retry policy for optimistic concurrency conflicts
208
+ retryPolicy: new ExponentialBackoffRetryPolicy({
209
+ maxRetries: 5,
210
+ initialDelayMs: 10,
211
+ maxDelayMs: 250,
212
+ }),
213
+ },
214
+ );
215
+
216
+ const note = await result;
217
+ return json(note);
218
+ },
219
+ }),
220
+
221
+ defineRoute({
222
+ method: "PATCH",
223
+ path: "/notes/:noteId",
224
+ inputSchema: z.object({ content: z.string() }),
225
+ outputSchema: z.object({
226
+ id: z.string(),
227
+ content: z.string(),
228
+ userId: z.string(),
229
+ createdAt: z.date(),
230
+ }),
231
+ errorCodes: [],
232
+ handler: async function ({ input, pathParams }, { json }) {
233
+ const { content } = await input.valid();
234
+ const noteId = pathParams.noteId;
235
+
236
+ // Handler controls transaction with optimistic concurrency control
237
+ const result = await this.uow(
238
+ async ({ executeMutate }) => {
239
+ const notePromise = services.updateNote(noteId, content);
240
+
241
+ // Execute with optimistic concurrency control
242
+ // If note was modified, whole transaction retries
243
+ await executeMutate();
244
+
245
+ return notePromise;
246
+ },
247
+ {
248
+ retryPolicy: new ExponentialBackoffRetryPolicy({
249
+ maxRetries: 5,
250
+ initialDelayMs: 10,
251
+ maxDelayMs: 250,
252
+ }),
253
+ },
254
+ );
95
255
 
96
- const note = await services.createNote({ content, userId });
256
+ const note = await result;
97
257
  return json(note);
98
258
  },
99
259
  }),
@@ -1,15 +1,28 @@
1
- import { column, idColumn, schema } from "@fragno-dev/db/schema";
1
+ import { column, idColumn, referenceColumn, schema } from "@fragno-dev/db/schema";
2
2
 
3
3
  export const noteSchema = schema((s) => {
4
- return s.addTable("note", (t) => {
5
- return t
6
- .addColumn("id", idColumn())
7
- .addColumn("content", column("string"))
8
- .addColumn("userId", column("string"))
9
- .addColumn(
10
- "createdAt",
11
- column("timestamp").defaultTo((b) => b.now()),
12
- )
13
- .createIndex("idx_note_user", ["userId"]);
14
- });
4
+ return s
5
+ .addTable("user", (t) => {
6
+ return t
7
+ .addColumn("id", idColumn())
8
+ .addColumn("name", column("string"))
9
+ .addColumn("email", column("string"))
10
+ .createIndex("idx_user_email", ["email"], { unique: true });
11
+ })
12
+ .addTable("note", (t) => {
13
+ return t
14
+ .addColumn("id", idColumn())
15
+ .addColumn("content", column("string"))
16
+ .addColumn("userId", referenceColumn())
17
+ .addColumn(
18
+ "createdAt",
19
+ column("timestamp").defaultTo((b) => b.now()),
20
+ )
21
+ .createIndex("idx_note_user", ["userId"]);
22
+ })
23
+ .addReference("author", {
24
+ type: "one",
25
+ from: { table: "note", column: "userId" },
26
+ to: { table: "user", column: "id" },
27
+ });
15
28
  });