@corpdk/create-ds 2026.10.0-alpha.1
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/canonical/.env.example +9 -0
- package/canonical/Dockerfile +66 -0
- package/canonical/LICENSE +21 -0
- package/canonical/codegen.ts +35 -0
- package/canonical/dal/dal.config.yaml +3 -0
- package/canonical/docker-compose.yml +37 -0
- package/canonical/docker-entrypoint.sh +6 -0
- package/canonical/drizzle.config.ts +10 -0
- package/canonical/package.json +55 -0
- package/canonical/src/db/index.ts +15 -0
- package/canonical/src/index.ts +27 -0
- package/canonical/src/schema.ts +21 -0
- package/canonical/tsconfig.json +9 -0
- package/dist/chunk-WALTUPRG.js +102 -0
- package/dist/index.js +430 -0
- package/dist/utils-RZJNRUXW.js +15 -0
- package/package.json +33 -0
- package/starter/dal/dal.config.yaml +3 -0
- package/starter/db/schema/index.ts +3 -0
- package/starter/db/schema/relations.ts +4 -0
- package/starter/db/schema/tags.ts +35 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
DS_PORT=
|
|
2
|
+
# GraphQL HTTP endpoint (queries, mutations, and subscriptions over SSE on the same URL).
|
|
3
|
+
# Example: http://localhost:4000/graphql
|
|
4
|
+
# Subscriptions: send the operation with header Accept: text/event-stream (POST JSON body or GET ?query=...).
|
|
5
|
+
# Matches templates/ds/docker-compose.yml (host port 5433 avoids conflict with local Postgres on 5432)
|
|
6
|
+
DATABASE_URL=postgresql://user:pass@localhost:5433/corpdk_ds
|
|
7
|
+
# Optional HMAC-SHA256 signing for pagination cursors (§13). When unset, cursors are unsigned (local dev).
|
|
8
|
+
# DAL_CURSOR_SECRET=
|
|
9
|
+
# REDIS_URL=redis://localhost:6379 # uncomment to switch pubsub to Redis/Valkey
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# syntax=docker/dockerfile:1
|
|
2
|
+
# Build from the monorepo root: docker build -f templates/ds/Dockerfile .
|
|
3
|
+
|
|
4
|
+
# ── Base ──────────────────────────────────────────────────────────────────────
|
|
5
|
+
FROM node:22-alpine AS base
|
|
6
|
+
ENV PNPM_HOME="/pnpm"
|
|
7
|
+
ENV PATH="$PNPM_HOME:$PATH"
|
|
8
|
+
RUN corepack enable
|
|
9
|
+
|
|
10
|
+
# ── Deps ──────────────────────────────────────────────────────────────────────
|
|
11
|
+
FROM base AS deps
|
|
12
|
+
WORKDIR /app
|
|
13
|
+
|
|
14
|
+
COPY package.json pnpm-workspace.yaml pnpm-lock.yaml tsconfig.base.json tsconfig.node.json ./
|
|
15
|
+
COPY templates/ds/package.json ./templates/ds/package.json
|
|
16
|
+
COPY templates/ds-sdk/package.json ./templates/ds-sdk/package.json
|
|
17
|
+
COPY templates/ds-cli/package.json ./templates/ds-cli/package.json
|
|
18
|
+
COPY libraries/dal-core/package.json ./libraries/dal-core/package.json
|
|
19
|
+
COPY libraries/dal-codegen/package.json ./libraries/dal-codegen/package.json
|
|
20
|
+
COPY libraries/pub-sub/package.json ./libraries/pub-sub/package.json
|
|
21
|
+
COPY libraries/codegen-cli/package.json ./libraries/codegen-cli/package.json
|
|
22
|
+
|
|
23
|
+
RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
|
|
24
|
+
pnpm install --frozen-lockfile
|
|
25
|
+
|
|
26
|
+
# ── Build ─────────────────────────────────────────────────────────────────────
|
|
27
|
+
FROM deps AS build
|
|
28
|
+
WORKDIR /app
|
|
29
|
+
|
|
30
|
+
COPY libraries/dal-core ./libraries/dal-core
|
|
31
|
+
COPY libraries/dal-codegen ./libraries/dal-codegen
|
|
32
|
+
COPY libraries/pub-sub ./libraries/pub-sub
|
|
33
|
+
COPY libraries/codegen-cli ./libraries/codegen-cli
|
|
34
|
+
COPY templates/ds-sdk ./templates/ds-sdk
|
|
35
|
+
COPY templates/ds-cli ./templates/ds-cli
|
|
36
|
+
COPY templates/ds ./templates/ds
|
|
37
|
+
|
|
38
|
+
RUN pnpm --filter @corpdk/dal-core build && \
|
|
39
|
+
pnpm --filter @corpdk/dal-codegen build && \
|
|
40
|
+
pnpm --filter @corpdk/pub-sub build && \
|
|
41
|
+
pnpm --filter @corpdk/codegen-cli build && \
|
|
42
|
+
pnpm --filter @corpdk/ds dal:codegen && \
|
|
43
|
+
pnpm --filter @corpdk/ds-sdk build && \
|
|
44
|
+
pnpm --filter @corpdk/ds build && \
|
|
45
|
+
pnpm --filter @corpdk/ds db:generate
|
|
46
|
+
|
|
47
|
+
# ── Runtime ───────────────────────────────────────────────────────────────────
|
|
48
|
+
FROM base AS runtime
|
|
49
|
+
ENV NODE_ENV=production
|
|
50
|
+
|
|
51
|
+
COPY --from=build /app/node_modules /app/node_modules
|
|
52
|
+
COPY --from=build /app/libraries/dal-core /app/libraries/dal-core
|
|
53
|
+
COPY --from=build /app/libraries/pub-sub /app/libraries/pub-sub
|
|
54
|
+
COPY --from=build /app/templates/ds/package.json /app/templates/ds/package.json
|
|
55
|
+
COPY --from=build /app/templates/ds/dist /app/templates/ds/dist
|
|
56
|
+
COPY --from=build /app/templates/ds/node_modules /app/templates/ds/node_modules
|
|
57
|
+
COPY --from=build /app/templates/ds/drizzle.config.ts /app/templates/ds/drizzle.config.ts
|
|
58
|
+
COPY --from=build /app/templates/ds/drizzle /app/templates/ds/drizzle
|
|
59
|
+
COPY --from=build /app/templates/ds/src/db/schema /app/templates/ds/src/db/schema
|
|
60
|
+
COPY templates/ds/docker-entrypoint.sh /app/templates/ds/docker-entrypoint.sh
|
|
61
|
+
RUN chmod +x /app/templates/ds/docker-entrypoint.sh
|
|
62
|
+
|
|
63
|
+
WORKDIR /app/templates/ds
|
|
64
|
+
USER node
|
|
65
|
+
EXPOSE 4000
|
|
66
|
+
ENTRYPOINT ["./docker-entrypoint.sh"]
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 CorpDK
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { CodegenConfig } from "@graphql-codegen/cli";
|
|
2
|
+
import { graphqlCodegenMappers } from "./src/generated/graphql-codegen.mappers.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Monorepo layout: this DS package must sit beside sibling `ds-sdk` and `ds-cli`
|
|
6
|
+
* packages (`../ds-sdk`, `../ds-cli`). `pnpm codegen` writes SDK and CLI artifacts
|
|
7
|
+
* there. DS-only repos outside this layout must add those packages or adjust paths.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const config: CodegenConfig = {
|
|
11
|
+
schema: ["./src/generated/generated-schema.ts"],
|
|
12
|
+
generates: {
|
|
13
|
+
"../ds-sdk/src/generated/": {
|
|
14
|
+
preset: "client",
|
|
15
|
+
presetConfig: { fragmentMasking: false },
|
|
16
|
+
},
|
|
17
|
+
"./src/generated/graphql/resolvers.generated.ts": {
|
|
18
|
+
plugins: ["typescript", "typescript-resolvers"],
|
|
19
|
+
config: {
|
|
20
|
+
contextType: "../dal/resolvers/generated-resolvers.js#DalContext",
|
|
21
|
+
useTypeImports: true,
|
|
22
|
+
mappers: { ...graphqlCodegenMappers },
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
"../ds-cli/src/generated/": {
|
|
26
|
+
preset: "@corpdk/codegen-cli",
|
|
27
|
+
presetConfig: {
|
|
28
|
+
httpUrlEnvVar: "DS_HTTP_URL",
|
|
29
|
+
wsUrlEnvVar: "DS_WS_URL",
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export default config;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
services:
|
|
2
|
+
postgres:
|
|
3
|
+
image: dhi.io/postgres:18-alpine3.23
|
|
4
|
+
container_name: corpdk-ds-postgres
|
|
5
|
+
restart: unless-stopped
|
|
6
|
+
ports:
|
|
7
|
+
- "${POSTGRES_HOST_PORT:-5433}:5432"
|
|
8
|
+
environment:
|
|
9
|
+
POSTGRES_USER: user
|
|
10
|
+
POSTGRES_PASSWORD: pass
|
|
11
|
+
POSTGRES_DB: corpdk_ds
|
|
12
|
+
volumes:
|
|
13
|
+
- corpdk_ds_pgdata:/var/lib/postgresql/data
|
|
14
|
+
healthcheck:
|
|
15
|
+
test: ["CMD-SHELL", "pg_isready -U user -d corpdk_ds"]
|
|
16
|
+
interval: 5s
|
|
17
|
+
timeout: 5s
|
|
18
|
+
retries: 5
|
|
19
|
+
start_period: 10s
|
|
20
|
+
|
|
21
|
+
ds:
|
|
22
|
+
build:
|
|
23
|
+
context: ../..
|
|
24
|
+
dockerfile: templates/ds/Dockerfile
|
|
25
|
+
container_name: corpdk-ds
|
|
26
|
+
restart: unless-stopped
|
|
27
|
+
depends_on:
|
|
28
|
+
postgres:
|
|
29
|
+
condition: service_healthy
|
|
30
|
+
ports:
|
|
31
|
+
- "${DS_HOST_PORT:-4000}:4000"
|
|
32
|
+
environment:
|
|
33
|
+
DS_PORT: "4000"
|
|
34
|
+
DATABASE_URL: postgresql://user:pass@postgres:5432/corpdk_ds
|
|
35
|
+
|
|
36
|
+
volumes:
|
|
37
|
+
corpdk_ds_pgdata:
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@corpdk/ds",
|
|
3
|
+
"description": "Primary GraphQL Yoga data service with Drizzle ORM (PostgreSQL, MySQL, SQLite, CockroachDB)",
|
|
4
|
+
"version": "2026.10.0-alpha.1",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"registry": "https://artifactory.corp.example.com/api/npm/npm-private/"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"dev": "node --env-file .env --import tsx/esm --watch src/index.ts",
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"codegen": "graphql-codegen",
|
|
13
|
+
"dal:codegen:schema": "node ./node_modules/@corpdk/dal-codegen/dist/cli.js --mode=schema",
|
|
14
|
+
"dal:codegen:impl": "node ./node_modules/@corpdk/dal-codegen/dist/cli.js --mode=impl",
|
|
15
|
+
"dal:codegen:bootstrap": "node ./node_modules/@corpdk/dal-codegen/dist/cli.js --mode=bootstrap",
|
|
16
|
+
"dal:codegen": "pnpm run dal:codegen:schema && pnpm run codegen && pnpm run dal:codegen:impl",
|
|
17
|
+
"entity:lint": "node ./node_modules/@corpdk/dal-codegen/dist/lint-cli.js",
|
|
18
|
+
"start": "node dist/src/index.js",
|
|
19
|
+
"lint": "eslint src/",
|
|
20
|
+
"typecheck": "tsc --noEmit",
|
|
21
|
+
"db:up": "docker compose up postgres -d",
|
|
22
|
+
"db:down": "docker compose down",
|
|
23
|
+
"compose:up": "docker compose up --build -d",
|
|
24
|
+
"compose:down": "docker compose down",
|
|
25
|
+
"compose:recreate": "docker compose up --build --force-recreate -d",
|
|
26
|
+
"db:generate": "drizzle-kit generate",
|
|
27
|
+
"db:migrate": "drizzle-kit migrate",
|
|
28
|
+
"db:seed": "node --env-file .env --import tsx/esm src/db/seed.ts",
|
|
29
|
+
"clean": "rm -rf dist node_modules .turbo *.tsbuildinfo"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@corpdk/dal-core": "workspace:*",
|
|
33
|
+
"@corpdk/pub-sub": "workspace:*",
|
|
34
|
+
"@graphql-yoga/redis-event-target": "^3.0.0",
|
|
35
|
+
"drizzle-orm": "^0.45.2",
|
|
36
|
+
"graphql": "^16.13.2",
|
|
37
|
+
"graphql-yoga": "^5.18.1",
|
|
38
|
+
"ioredis": "^5.10.1",
|
|
39
|
+
"pg": "^8.20.0"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@corpdk/codegen-cli": "workspace:*",
|
|
43
|
+
"@corpdk/dal-codegen": "workspace:*",
|
|
44
|
+
"@graphql-codegen/cli": "^6.2.1",
|
|
45
|
+
"@graphql-codegen/client-preset": "^5.2.4",
|
|
46
|
+
"@graphql-codegen/typescript": "^5.0.9",
|
|
47
|
+
"@graphql-codegen/typescript-resolvers": "^5.1.7",
|
|
48
|
+
"@types/node": "^20.19.37",
|
|
49
|
+
"@types/pg": "^8.11.14",
|
|
50
|
+
"drizzle-kit": "^0.31.10",
|
|
51
|
+
"tsx": "^4.21.0",
|
|
52
|
+
"typescript": "^6.0.2"
|
|
53
|
+
},
|
|
54
|
+
"license": "MIT"
|
|
55
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { drizzle } from "drizzle-orm/node-postgres";
|
|
2
|
+
import { Pool } from "pg";
|
|
3
|
+
import * as schema from "./schema/index.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Drizzle database instance.
|
|
7
|
+
*
|
|
8
|
+
* The connection string is read from DATABASE_URL at startup.
|
|
9
|
+
* When create-app scaffolds with a different SQL dialect (MySQL, SQLite,
|
|
10
|
+
* CockroachDB), it updates drizzle.config.ts, src/db/schema/, and
|
|
11
|
+
* swaps the driver package in package.json — update this file accordingly.
|
|
12
|
+
*/
|
|
13
|
+
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
|
|
14
|
+
|
|
15
|
+
export const db = drizzle(pool, { schema });
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createServer } from "node:http";
|
|
2
|
+
import { createYoga } from "graphql-yoga";
|
|
3
|
+
import { schema, createRequestContext } from "./schema.js";
|
|
4
|
+
|
|
5
|
+
const PORT = Number(process.env.DS_PORT);
|
|
6
|
+
if (!PORT) throw new Error("DS_PORT env var is required");
|
|
7
|
+
|
|
8
|
+
const yoga = createYoga({
|
|
9
|
+
schema,
|
|
10
|
+
context: () => {
|
|
11
|
+
// Auth plugin would resolve actorId from session/JWT and pass it here.
|
|
12
|
+
const actorId: string | null = null;
|
|
13
|
+
return createRequestContext({ actorId });
|
|
14
|
+
},
|
|
15
|
+
graphiql: process.env.NODE_ENV !== "production",
|
|
16
|
+
logging: true,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const server = createServer(yoga);
|
|
20
|
+
|
|
21
|
+
server.listen(PORT, () => {
|
|
22
|
+
const base = `http://localhost:${PORT}/graphql`;
|
|
23
|
+
console.log(`@corpdk/ds HTTP ${base}`);
|
|
24
|
+
console.log(
|
|
25
|
+
`@corpdk/ds SSE ${base} (subscriptions: Accept: text/event-stream)`,
|
|
26
|
+
);
|
|
27
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { createSchema } from "graphql-yoga";
|
|
2
|
+
import { typeDefs } from "./generated/generated-schema.js";
|
|
3
|
+
import {
|
|
4
|
+
generatedResolvers,
|
|
5
|
+
createDalContext,
|
|
6
|
+
pubsub,
|
|
7
|
+
} from "./generated/dal/index.js";
|
|
8
|
+
|
|
9
|
+
export const schema = createSchema({
|
|
10
|
+
typeDefs,
|
|
11
|
+
resolvers: generatedResolvers,
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export interface RequestContextOptions {
|
|
15
|
+
/** Set by auth plugin from session/token; null until auth is wired. */
|
|
16
|
+
actorId?: string | null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function createRequestContext(options?: RequestContextOptions) {
|
|
20
|
+
return createDalContext(pubsub, { actorId: options?.actorId ?? null });
|
|
21
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/utils.ts
|
|
4
|
+
import fs from "fs/promises";
|
|
5
|
+
import path from "path";
|
|
6
|
+
import { exec } from "child_process";
|
|
7
|
+
import { promisify } from "util";
|
|
8
|
+
var execAsync = promisify(exec);
|
|
9
|
+
async function pathExists(p) {
|
|
10
|
+
try {
|
|
11
|
+
await fs.access(p);
|
|
12
|
+
return true;
|
|
13
|
+
} catch {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
async function readJson(filePath) {
|
|
18
|
+
const content = await fs.readFile(filePath, "utf8");
|
|
19
|
+
return JSON.parse(content);
|
|
20
|
+
}
|
|
21
|
+
async function writeJson(filePath, data) {
|
|
22
|
+
await fs.mkdir(path.dirname(filePath), { recursive: true });
|
|
23
|
+
await fs.writeFile(filePath, JSON.stringify(data, null, 2) + "\n", "utf8");
|
|
24
|
+
}
|
|
25
|
+
var COPY_EXCLUDE_SEGMENTS = /* @__PURE__ */ new Set([
|
|
26
|
+
"node_modules",
|
|
27
|
+
".turbo",
|
|
28
|
+
"dist",
|
|
29
|
+
".next",
|
|
30
|
+
"generated",
|
|
31
|
+
"drizzle",
|
|
32
|
+
"src"
|
|
33
|
+
]);
|
|
34
|
+
var COPY_EXCLUDE_GLOB = ["*.tsbuildinfo", ".env"];
|
|
35
|
+
function matchGlob(pattern, name) {
|
|
36
|
+
if (pattern.startsWith("*")) return name.endsWith(pattern.slice(1));
|
|
37
|
+
if (pattern.endsWith("*")) return name.startsWith(pattern.slice(0, -1));
|
|
38
|
+
return name === pattern;
|
|
39
|
+
}
|
|
40
|
+
function isExcluded(relPath, extraExclude) {
|
|
41
|
+
const segments = relPath.split(path.sep);
|
|
42
|
+
const allSegments = /* @__PURE__ */ new Set([...COPY_EXCLUDE_SEGMENTS, ...extraExclude]);
|
|
43
|
+
for (const seg of segments) {
|
|
44
|
+
if (allSegments.has(seg)) return true;
|
|
45
|
+
for (const pattern of COPY_EXCLUDE_GLOB) {
|
|
46
|
+
if (matchGlob(pattern, seg)) return true;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
async function copyDir(src, dest, options = {}) {
|
|
52
|
+
const { extraExclude = [], transform, skipIfExists = false } = options;
|
|
53
|
+
if (!await pathExists(src)) return;
|
|
54
|
+
await fs.mkdir(dest, { recursive: true });
|
|
55
|
+
const entries = await fs.readdir(src, { withFileTypes: true });
|
|
56
|
+
for (const entry of entries) {
|
|
57
|
+
const srcPath = path.join(src, entry.name);
|
|
58
|
+
const relPath = entry.name;
|
|
59
|
+
if (isExcluded(relPath, extraExclude)) continue;
|
|
60
|
+
const destPath = path.join(dest, entry.name);
|
|
61
|
+
if (entry.isDirectory()) {
|
|
62
|
+
await copyDirRecursive(srcPath, destPath, relPath, {
|
|
63
|
+
extraExclude,
|
|
64
|
+
transform,
|
|
65
|
+
skipIfExists
|
|
66
|
+
});
|
|
67
|
+
} else if (entry.isFile()) {
|
|
68
|
+
if (skipIfExists && await pathExists(destPath)) continue;
|
|
69
|
+
const raw = await fs.readFile(srcPath, "utf8");
|
|
70
|
+
const content = transform ? transform(raw, relPath) : raw;
|
|
71
|
+
await fs.mkdir(path.dirname(destPath), { recursive: true });
|
|
72
|
+
await fs.writeFile(destPath, content, "utf8");
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async function copyDirRecursive(src, dest, relPrefix, options) {
|
|
77
|
+
await fs.mkdir(dest, { recursive: true });
|
|
78
|
+
const entries = await fs.readdir(src, { withFileTypes: true });
|
|
79
|
+
for (const entry of entries) {
|
|
80
|
+
const srcPath = path.join(src, entry.name);
|
|
81
|
+
const relPath = path.join(relPrefix, entry.name);
|
|
82
|
+
if (isExcluded(relPath, options.extraExclude)) continue;
|
|
83
|
+
const destPath = path.join(dest, entry.name);
|
|
84
|
+
if (entry.isDirectory()) {
|
|
85
|
+
await copyDirRecursive(srcPath, destPath, relPath, options);
|
|
86
|
+
} else if (entry.isFile()) {
|
|
87
|
+
if (options.skipIfExists && await pathExists(destPath)) continue;
|
|
88
|
+
const raw = await fs.readFile(srcPath, "utf8");
|
|
89
|
+
const content = options.transform ? options.transform(raw, relPath) : raw;
|
|
90
|
+
await fs.mkdir(path.dirname(destPath), { recursive: true });
|
|
91
|
+
await fs.writeFile(destPath, content, "utf8");
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export {
|
|
97
|
+
execAsync,
|
|
98
|
+
pathExists,
|
|
99
|
+
readJson,
|
|
100
|
+
writeJson,
|
|
101
|
+
copyDir
|
|
102
|
+
};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
copyDir,
|
|
4
|
+
execAsync,
|
|
5
|
+
pathExists,
|
|
6
|
+
readJson,
|
|
7
|
+
writeJson
|
|
8
|
+
} from "./chunk-WALTUPRG.js";
|
|
9
|
+
|
|
10
|
+
// src/index.ts
|
|
11
|
+
import { outro } from "@clack/prompts";
|
|
12
|
+
|
|
13
|
+
// src/args.ts
|
|
14
|
+
function printHelp() {
|
|
15
|
+
console.log(`@corpdk/create-ds \u2014 scaffold and upgrade DAL-automated DS packages
|
|
16
|
+
|
|
17
|
+
Usage:
|
|
18
|
+
create-ds init [directory] [options]
|
|
19
|
+
create-ds upgrade [directory] [options]
|
|
20
|
+
|
|
21
|
+
Commands:
|
|
22
|
+
init Scaffold a minimal DS package (Drizzle schema + dal.config + scripts)
|
|
23
|
+
upgrade Merge canonical template deltas; never overwrites src/db/schema/**
|
|
24
|
+
|
|
25
|
+
Options:
|
|
26
|
+
--name <pkg> npm package name (default: @corpdk/ds)
|
|
27
|
+
--demo-schema Copy full demo commerce schema + seed from templates/ds
|
|
28
|
+
-h, --help Show this help
|
|
29
|
+
|
|
30
|
+
Examples:
|
|
31
|
+
create-ds init ./packages/my-ds --name @myorg/my-ds
|
|
32
|
+
create-ds upgrade ./packages/my-ds
|
|
33
|
+
create-ds upgrade # upgrades current working directory
|
|
34
|
+
`);
|
|
35
|
+
}
|
|
36
|
+
function parseArgs(argv) {
|
|
37
|
+
const args = argv.slice(2);
|
|
38
|
+
const result = {
|
|
39
|
+
command: null,
|
|
40
|
+
targetDir: process.cwd(),
|
|
41
|
+
packageName: "@corpdk/ds",
|
|
42
|
+
withDemoSchema: false
|
|
43
|
+
};
|
|
44
|
+
if (args.length === 0 || args.includes("--help") || args.includes("-h")) {
|
|
45
|
+
result.command = "help";
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
const cmd = args[0];
|
|
49
|
+
if (cmd === "init" || cmd === "upgrade") {
|
|
50
|
+
result.command = cmd;
|
|
51
|
+
} else {
|
|
52
|
+
result.command = "help";
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
let i = 1;
|
|
56
|
+
while (i < args.length) {
|
|
57
|
+
const arg = args[i];
|
|
58
|
+
if (arg === "--name" && args[i + 1]) {
|
|
59
|
+
result.packageName = args[++i];
|
|
60
|
+
i++;
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
if (arg === "--demo-schema") {
|
|
64
|
+
result.withDemoSchema = true;
|
|
65
|
+
i++;
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
if (!arg.startsWith("-")) {
|
|
69
|
+
result.targetDir = arg;
|
|
70
|
+
i++;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
i++;
|
|
74
|
+
}
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// src/init.ts
|
|
79
|
+
import fs from "fs/promises";
|
|
80
|
+
import path2 from "path";
|
|
81
|
+
import { spinner } from "@clack/prompts";
|
|
82
|
+
|
|
83
|
+
// src/template.ts
|
|
84
|
+
import path from "path";
|
|
85
|
+
import { fileURLToPath } from "url";
|
|
86
|
+
var __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
87
|
+
function repoRootFromEngine() {
|
|
88
|
+
return path.resolve(__dirname, "..", "..", "..");
|
|
89
|
+
}
|
|
90
|
+
async function resolveCanonicalDsTemplateDir(repoRoot) {
|
|
91
|
+
const monorepoTemplate = path.join(repoRoot, "templates", "ds");
|
|
92
|
+
const bundled = path.resolve(__dirname, "..", "canonical");
|
|
93
|
+
const { pathExists: pathExists2 } = await import("./utils-RZJNRUXW.js");
|
|
94
|
+
if (await pathExists2(path.join(monorepoTemplate, "package.json"))) {
|
|
95
|
+
return monorepoTemplate;
|
|
96
|
+
}
|
|
97
|
+
if (await pathExists2(path.join(bundled, "package.json"))) {
|
|
98
|
+
return bundled;
|
|
99
|
+
}
|
|
100
|
+
throw new Error(
|
|
101
|
+
"Canonical DS template not found (expected templates/ds or bundled canonical/)"
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
function engineStarterDir() {
|
|
105
|
+
return path.resolve(__dirname, "..", "starter");
|
|
106
|
+
}
|
|
107
|
+
function isBundledCanonicalTemplate(templateDir) {
|
|
108
|
+
const bundled = path.resolve(__dirname, "..", "canonical");
|
|
109
|
+
return path.resolve(templateDir) === bundled;
|
|
110
|
+
}
|
|
111
|
+
async function readCreateDsReleaseVersion() {
|
|
112
|
+
const { readJson: readJson2 } = await import("./utils-RZJNRUXW.js");
|
|
113
|
+
const pkg = await readJson2(
|
|
114
|
+
path.resolve(__dirname, "..", "package.json")
|
|
115
|
+
);
|
|
116
|
+
if (!pkg.version) {
|
|
117
|
+
throw new Error("create-ds package.json missing version");
|
|
118
|
+
}
|
|
119
|
+
return pkg.version;
|
|
120
|
+
}
|
|
121
|
+
function initialScaffoldCalVer(asOf = /* @__PURE__ */ new Date()) {
|
|
122
|
+
const year = asOf.getUTCFullYear();
|
|
123
|
+
const month = asOf.getUTCMonth() + 1;
|
|
124
|
+
return `${year}.${month}.0`;
|
|
125
|
+
}
|
|
126
|
+
var UPGRADE_RELATIVE_FILES = [
|
|
127
|
+
"LICENSE",
|
|
128
|
+
"package.json",
|
|
129
|
+
"dal/dal.config.yaml",
|
|
130
|
+
"codegen.ts",
|
|
131
|
+
"drizzle.config.ts",
|
|
132
|
+
"tsconfig.json",
|
|
133
|
+
"Dockerfile",
|
|
134
|
+
"docker-compose.yml",
|
|
135
|
+
"docker-entrypoint.sh",
|
|
136
|
+
".gitignore",
|
|
137
|
+
".env.example",
|
|
138
|
+
"src/schema.ts",
|
|
139
|
+
"src/index.ts",
|
|
140
|
+
"src/db/index.ts"
|
|
141
|
+
];
|
|
142
|
+
|
|
143
|
+
// src/package-merge.ts
|
|
144
|
+
var CONSUMER_PRESERVED_TOP_LEVEL = [
|
|
145
|
+
"private",
|
|
146
|
+
"license",
|
|
147
|
+
"engines",
|
|
148
|
+
"packageManager",
|
|
149
|
+
"author",
|
|
150
|
+
"repository",
|
|
151
|
+
"bugs",
|
|
152
|
+
"homepage",
|
|
153
|
+
"keywords"
|
|
154
|
+
];
|
|
155
|
+
var CORP_DK_BUMP = /* @__PURE__ */ new Set([
|
|
156
|
+
"@corpdk/dal-core",
|
|
157
|
+
"@corpdk/pub-sub",
|
|
158
|
+
"@corpdk/codegen-cli",
|
|
159
|
+
"@corpdk/dal-codegen"
|
|
160
|
+
]);
|
|
161
|
+
var DAL_CODEGEN_CLI = "node ./node_modules/@corpdk/dal-codegen/dist/cli.js";
|
|
162
|
+
var DAL_ENTITY_LINT_CLI = "node ./node_modules/@corpdk/dal-codegen/dist/lint-cli.js";
|
|
163
|
+
function normalizeDalScripts(scripts) {
|
|
164
|
+
const out = { ...scripts };
|
|
165
|
+
out["dal:codegen:schema"] = `${DAL_CODEGEN_CLI} --mode=schema`;
|
|
166
|
+
out["dal:codegen:impl"] = `${DAL_CODEGEN_CLI} --mode=impl`;
|
|
167
|
+
out["dal:codegen:bootstrap"] = `${DAL_CODEGEN_CLI} --mode=bootstrap`;
|
|
168
|
+
out["entity:lint"] = DAL_ENTITY_LINT_CLI;
|
|
169
|
+
return out;
|
|
170
|
+
}
|
|
171
|
+
function rewriteCorpdkWorkspaceDeps(deps, releaseVersion) {
|
|
172
|
+
if (!deps) return {};
|
|
173
|
+
const out = { ...deps };
|
|
174
|
+
for (const [key, value] of Object.entries(out)) {
|
|
175
|
+
if (key.startsWith("@corpdk/") && value === "workspace:*") {
|
|
176
|
+
out[key] = `^${releaseVersion}`;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return out;
|
|
180
|
+
}
|
|
181
|
+
function mergeConsumerDeps(templateDeps, consumerDeps) {
|
|
182
|
+
const merged = templateDeps ? { ...templateDeps } : {};
|
|
183
|
+
if (!consumerDeps) return merged;
|
|
184
|
+
for (const [key, value] of Object.entries(consumerDeps)) {
|
|
185
|
+
if (!CORP_DK_BUMP.has(key)) {
|
|
186
|
+
merged[key] = value;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return merged;
|
|
190
|
+
}
|
|
191
|
+
function copyPreservedConsumerFields(merged, consumer) {
|
|
192
|
+
for (const key of CONSUMER_PRESERVED_TOP_LEVEL) {
|
|
193
|
+
if (Object.prototype.hasOwnProperty.call(consumer, key)) {
|
|
194
|
+
merged[key] = consumer[key];
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
function mergePackageJson(consumer, template, options) {
|
|
199
|
+
const merged = {
|
|
200
|
+
...template,
|
|
201
|
+
name: consumer.name ?? template.name,
|
|
202
|
+
version: consumer.version ?? template.version,
|
|
203
|
+
description: consumer.description ?? template.description,
|
|
204
|
+
publishConfig: consumer.publishConfig,
|
|
205
|
+
scripts: normalizeDalScripts(template.scripts ?? {}),
|
|
206
|
+
dependencies: mergeConsumerDeps(
|
|
207
|
+
template.dependencies,
|
|
208
|
+
consumer.dependencies
|
|
209
|
+
),
|
|
210
|
+
devDependencies: mergeConsumerDeps(
|
|
211
|
+
template.devDependencies,
|
|
212
|
+
consumer.devDependencies
|
|
213
|
+
)
|
|
214
|
+
};
|
|
215
|
+
if (options?.publishedCorpdkVersions) {
|
|
216
|
+
merged.dependencies = rewriteCorpdkWorkspaceDeps(
|
|
217
|
+
merged.dependencies,
|
|
218
|
+
options.publishedCorpdkVersions
|
|
219
|
+
);
|
|
220
|
+
merged.devDependencies = rewriteCorpdkWorkspaceDeps(
|
|
221
|
+
merged.devDependencies,
|
|
222
|
+
options.publishedCorpdkVersions
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
copyPreservedConsumerFields(merged, consumer);
|
|
226
|
+
return merged;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// src/init.ts
|
|
230
|
+
async function runInit(options) {
|
|
231
|
+
const s = spinner();
|
|
232
|
+
const templateDir = await resolveCanonicalDsTemplateDir(options.repoRoot);
|
|
233
|
+
const targetDir = path2.resolve(options.targetDir);
|
|
234
|
+
const dalCodegenCli = path2.join(
|
|
235
|
+
options.repoRoot,
|
|
236
|
+
"libraries/dal-codegen/dist/cli.js"
|
|
237
|
+
);
|
|
238
|
+
if (!await pathExists(templateDir)) {
|
|
239
|
+
throw new Error(`Canonical DS template not found: ${templateDir}`);
|
|
240
|
+
}
|
|
241
|
+
if (await pathExists(targetDir)) {
|
|
242
|
+
const entries = await fs.readdir(targetDir);
|
|
243
|
+
if (entries.length > 0) {
|
|
244
|
+
throw new Error(`Target directory is not empty: ${targetDir}`);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
s.start("Scaffolding DS package layout");
|
|
248
|
+
await fs.mkdir(targetDir, { recursive: true });
|
|
249
|
+
await copyDir(templateDir, targetDir, {
|
|
250
|
+
extraExclude: ["src", "drizzle"]
|
|
251
|
+
});
|
|
252
|
+
const schemaSrc = options.withDemoSchema ? path2.join(templateDir, "src", "db", "schema") : path2.join(engineStarterDir(), "db", "schema");
|
|
253
|
+
await copyDir(schemaSrc, path2.join(targetDir, "src", "db", "schema"));
|
|
254
|
+
if (options.withDemoSchema) {
|
|
255
|
+
const seedSrc = path2.join(templateDir, "src", "db", "seed.ts");
|
|
256
|
+
if (await pathExists(seedSrc)) {
|
|
257
|
+
await fs.copyFile(seedSrc, path2.join(targetDir, "src", "db", "seed.ts"));
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
const starterDal = path2.join(engineStarterDir(), "dal", "dal.config.yaml");
|
|
261
|
+
if (!options.withDemoSchema && await pathExists(starterDal)) {
|
|
262
|
+
await fs.copyFile(
|
|
263
|
+
starterDal,
|
|
264
|
+
path2.join(targetDir, "dal", "dal.config.yaml")
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
const templatePkg = await readJson(
|
|
268
|
+
path2.join(templateDir, "package.json")
|
|
269
|
+
);
|
|
270
|
+
const mergeOptions = isBundledCanonicalTemplate(templateDir) ? { publishedCorpdkVersions: await readCreateDsReleaseVersion() } : void 0;
|
|
271
|
+
const merged = mergePackageJson(
|
|
272
|
+
{
|
|
273
|
+
name: options.packageName,
|
|
274
|
+
version: initialScaffoldCalVer(),
|
|
275
|
+
license: "MIT"
|
|
276
|
+
},
|
|
277
|
+
templatePkg,
|
|
278
|
+
mergeOptions
|
|
279
|
+
);
|
|
280
|
+
await writeJson(path2.join(targetDir, "package.json"), merged);
|
|
281
|
+
if (await pathExists(dalCodegenCli)) {
|
|
282
|
+
await execAsync(`node "${dalCodegenCli}" --mode=bootstrap`, {
|
|
283
|
+
cwd: targetDir
|
|
284
|
+
});
|
|
285
|
+
} else {
|
|
286
|
+
for (const rel of ["src/schema.ts", "src/index.ts", "src/db/index.ts"]) {
|
|
287
|
+
await fs.copyFile(path2.join(templateDir, rel), path2.join(targetDir, rel));
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
s.stop("DS package scaffolded");
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// src/upgrade.ts
|
|
294
|
+
import fs2 from "fs/promises";
|
|
295
|
+
import path3 from "path";
|
|
296
|
+
import { parse as parseYaml, stringify as stringifyYaml } from "yaml";
|
|
297
|
+
import { spinner as spinner2 } from "@clack/prompts";
|
|
298
|
+
function mergeDalConfig(templateRaw, consumerRaw) {
|
|
299
|
+
const template = parseYaml(templateRaw) ?? {};
|
|
300
|
+
const consumer = consumerRaw ? parseYaml(consumerRaw) ?? {} : {};
|
|
301
|
+
return stringifyYaml({ ...template, ...consumer });
|
|
302
|
+
}
|
|
303
|
+
async function mergeUpgradePackageJson(templatePath, destPath, mergeOptions) {
|
|
304
|
+
const consumer = await readJson(destPath);
|
|
305
|
+
const template = await readJson(templatePath);
|
|
306
|
+
await writeJson(destPath, mergePackageJson(consumer, template, mergeOptions));
|
|
307
|
+
}
|
|
308
|
+
async function mergeUpgradeDalConfig(templatePath, destPath) {
|
|
309
|
+
const templateRaw = await fs2.readFile(templatePath, "utf8");
|
|
310
|
+
const consumerRaw = await pathExists(destPath) ? await fs2.readFile(destPath, "utf8") : null;
|
|
311
|
+
await fs2.mkdir(path3.dirname(destPath), { recursive: true });
|
|
312
|
+
await fs2.writeFile(
|
|
313
|
+
destPath,
|
|
314
|
+
mergeDalConfig(templateRaw, consumerRaw),
|
|
315
|
+
"utf8"
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
async function copyUpgradeRelativeFile(rel, templateDir, packageDir, mergeOptions) {
|
|
319
|
+
const templatePath = path3.join(templateDir, rel);
|
|
320
|
+
const destPath = path3.join(packageDir, rel);
|
|
321
|
+
if (!await pathExists(templatePath)) return;
|
|
322
|
+
if (rel === "package.json") {
|
|
323
|
+
await mergeUpgradePackageJson(templatePath, destPath, mergeOptions);
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
if (rel === "dal/dal.config.yaml") {
|
|
327
|
+
await mergeUpgradeDalConfig(templatePath, destPath);
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
await fs2.mkdir(path3.dirname(destPath), { recursive: true });
|
|
331
|
+
await fs2.copyFile(templatePath, destPath);
|
|
332
|
+
}
|
|
333
|
+
async function runEntityLintIfAvailable(repoRoot, packageDir) {
|
|
334
|
+
const dalCodegenLint = path3.join(
|
|
335
|
+
repoRoot,
|
|
336
|
+
"libraries/dal-codegen/dist/lint-cli.js"
|
|
337
|
+
);
|
|
338
|
+
const localEntityLint = path3.join(
|
|
339
|
+
packageDir,
|
|
340
|
+
"node_modules/.bin/dal-entity-lint"
|
|
341
|
+
);
|
|
342
|
+
const canRunEntityLint = await pathExists(dalCodegenLint) || await pathExists(localEntityLint);
|
|
343
|
+
if (!canRunEntityLint) return;
|
|
344
|
+
const s = spinner2();
|
|
345
|
+
s.start("Running entity:lint");
|
|
346
|
+
try {
|
|
347
|
+
if (await pathExists(dalCodegenLint)) {
|
|
348
|
+
await execAsync(`node "${dalCodegenLint}"`, { cwd: packageDir });
|
|
349
|
+
} else {
|
|
350
|
+
await execAsync("pnpm exec dal-entity-lint", { cwd: packageDir });
|
|
351
|
+
}
|
|
352
|
+
s.stop("entity:lint passed");
|
|
353
|
+
} catch (err) {
|
|
354
|
+
s.stop("entity:lint reported issues (see output above)");
|
|
355
|
+
if (err instanceof Error && "stderr" in err) {
|
|
356
|
+
console.error(String(err.stderr ?? err.message));
|
|
357
|
+
}
|
|
358
|
+
throw err;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
async function runUpgrade(options) {
|
|
362
|
+
const s = spinner2();
|
|
363
|
+
const packageDir = path3.resolve(options.packageDir);
|
|
364
|
+
const templateDir = await resolveCanonicalDsTemplateDir(options.repoRoot);
|
|
365
|
+
if (!await pathExists(path3.join(packageDir, "dal/dal.config.yaml"))) {
|
|
366
|
+
throw new Error(
|
|
367
|
+
`Not a DAL DS package (missing dal/dal.config.yaml): ${packageDir}`
|
|
368
|
+
);
|
|
369
|
+
}
|
|
370
|
+
if (!await pathExists(templateDir)) {
|
|
371
|
+
throw new Error(`Canonical DS template not found: ${templateDir}`);
|
|
372
|
+
}
|
|
373
|
+
s.start("Merging automation stack from canonical template");
|
|
374
|
+
const mergeOptions = isBundledCanonicalTemplate(templateDir) ? { publishedCorpdkVersions: await readCreateDsReleaseVersion() } : void 0;
|
|
375
|
+
for (const rel of UPGRADE_RELATIVE_FILES) {
|
|
376
|
+
await copyUpgradeRelativeFile(rel, templateDir, packageDir, mergeOptions);
|
|
377
|
+
}
|
|
378
|
+
s.stop("Template deltas merged (src/db/schema/** untouched)");
|
|
379
|
+
await runEntityLintIfAvailable(options.repoRoot, packageDir);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// src/index.ts
|
|
383
|
+
async function main() {
|
|
384
|
+
const parsed = parseArgs(process.argv);
|
|
385
|
+
if (parsed.command === "help" || parsed.command === null) {
|
|
386
|
+
printHelp();
|
|
387
|
+
process.exit(parsed.command === "help" ? 0 : 1);
|
|
388
|
+
}
|
|
389
|
+
const repoRoot = repoRootFromEngine();
|
|
390
|
+
if (parsed.command === "init") {
|
|
391
|
+
await runInit({
|
|
392
|
+
targetDir: parsed.targetDir,
|
|
393
|
+
repoRoot,
|
|
394
|
+
packageName: parsed.packageName,
|
|
395
|
+
withDemoSchema: parsed.withDemoSchema
|
|
396
|
+
});
|
|
397
|
+
outro(
|
|
398
|
+
`DS package ready at:
|
|
399
|
+
${parsed.targetDir}
|
|
400
|
+
|
|
401
|
+
Next steps:
|
|
402
|
+
cd ${parsed.targetDir}
|
|
403
|
+
pnpm install
|
|
404
|
+
pnpm dal:codegen
|
|
405
|
+
`
|
|
406
|
+
);
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
if (parsed.command === "upgrade") {
|
|
410
|
+
await runUpgrade({
|
|
411
|
+
packageDir: parsed.targetDir,
|
|
412
|
+
repoRoot
|
|
413
|
+
});
|
|
414
|
+
outro(
|
|
415
|
+
`Upgrade complete for:
|
|
416
|
+
${parsed.targetDir}
|
|
417
|
+
|
|
418
|
+
Next steps:
|
|
419
|
+
pnpm install
|
|
420
|
+
pnpm dal:codegen
|
|
421
|
+
`
|
|
422
|
+
);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
try {
|
|
426
|
+
await main();
|
|
427
|
+
} catch (err) {
|
|
428
|
+
console.error(err instanceof Error ? err.message : err);
|
|
429
|
+
process.exit(1);
|
|
430
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@corpdk/create-ds",
|
|
3
|
+
"version": "2026.10.0-alpha.1",
|
|
4
|
+
"description": "Scaffold and upgrade DAL-automated GraphQL data services",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"registry": "https://registry.npmjs.org/",
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"starter",
|
|
13
|
+
"canonical"
|
|
14
|
+
],
|
|
15
|
+
"bin": {
|
|
16
|
+
"create-ds": "./dist/index.js"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@clack/prompts": "^1.1.0",
|
|
20
|
+
"yaml": "^2.8.3"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@types/node": "^20.19.37",
|
|
24
|
+
"tsup": "^8.5.1",
|
|
25
|
+
"typescript": "^6.0.2"
|
|
26
|
+
},
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "tsup",
|
|
30
|
+
"dev": "tsup --watch",
|
|
31
|
+
"clean": "rm -rf dist node_modules .turbo"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { sql } from "drizzle-orm";
|
|
2
|
+
import {
|
|
3
|
+
check,
|
|
4
|
+
index,
|
|
5
|
+
pgTable,
|
|
6
|
+
text,
|
|
7
|
+
timestamp,
|
|
8
|
+
uuid,
|
|
9
|
+
varchar,
|
|
10
|
+
} from "drizzle-orm/pg-core";
|
|
11
|
+
|
|
12
|
+
/** Starter tag entity — replace or extend as your domain grows. */
|
|
13
|
+
export const tags = pgTable(
|
|
14
|
+
"tags",
|
|
15
|
+
{
|
|
16
|
+
/** Surrogate primary key. */
|
|
17
|
+
id: uuid("id").primaryKey().defaultRandom(),
|
|
18
|
+
/** Unique tag label (case-sensitive); 2–30 characters. */
|
|
19
|
+
label: varchar("label", { length: 30 }).notNull(),
|
|
20
|
+
/** Soft-delete timestamp (UTC); NULL = active row. */
|
|
21
|
+
deletedAt: timestamp("deleted_at", { withTimezone: true }),
|
|
22
|
+
/** Actor ID who soft-deleted this row. */
|
|
23
|
+
deletedBy: text("deleted_by"),
|
|
24
|
+
/** Row creation time (UTC). */
|
|
25
|
+
createdAt: timestamp("created_at", { withTimezone: true })
|
|
26
|
+
.notNull()
|
|
27
|
+
.defaultNow(),
|
|
28
|
+
/** Actor ID from request context; never client-supplied. */
|
|
29
|
+
createdBy: text("created_by").notNull(),
|
|
30
|
+
},
|
|
31
|
+
(table) => [
|
|
32
|
+
index("tags_label_idx").on(table.label),
|
|
33
|
+
check("tags_label_min_length", sql`char_length(${table.label}) >= 2`),
|
|
34
|
+
],
|
|
35
|
+
);
|