@fakeware/core 0.0.5 → 0.0.7

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,52 +1,2 @@
1
- import { z } from "zod";
2
-
3
- //#region src/config/schema.d.ts
4
- declare const shopwareSchema: z.ZodObject<{
5
- url: z.ZodString;
6
- clientId: z.ZodString;
7
- clientSecret: z.ZodString;
8
- }, z.core.$strip>;
9
- declare const mediaSchema: z.ZodObject<{
10
- provider: z.ZodString;
11
- perProduct: z.ZodOptional<z.ZodObject<{
12
- min: z.ZodNumber;
13
- max: z.ZodNumber;
14
- }, z.core.$strip>>;
15
- }, z.core.$strip>;
16
- declare const pluginRefSchema: z.ZodUnion<readonly [z.ZodString, z.ZodTuple<[z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>], null>]>;
17
- declare const fakewareConfigSchema: z.ZodObject<{
18
- extends: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
19
- shopware: z.ZodOptional<z.ZodObject<{
20
- url: z.ZodString;
21
- clientId: z.ZodString;
22
- clientSecret: z.ZodString;
23
- }, z.core.$strip>>;
24
- locale: z.ZodOptional<z.ZodString>;
25
- seed: z.ZodOptional<z.ZodString>;
26
- batchSize: z.ZodDefault<z.ZodNumber>;
27
- generators: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
28
- media: z.ZodOptional<z.ZodObject<{
29
- provider: z.ZodString;
30
- perProduct: z.ZodOptional<z.ZodObject<{
31
- min: z.ZodNumber;
32
- max: z.ZodNumber;
33
- }, z.core.$strip>>;
34
- }, z.core.$strip>>;
35
- scenario: z.ZodOptional<z.ZodString>;
36
- scenarios: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
37
- plugins: z.ZodDefault<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodTuple<[z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>], null>]>>>;
38
- }, z.core.$strip>;
39
- type FakewareConfig = z.output<typeof fakewareConfigSchema>;
40
- type FakewareUserConfig = z.input<typeof fakewareConfigSchema>;
41
- //#endregion
42
- //#region src/config/define.d.ts
43
- interface ConfigEnv {
44
- env: Record<string, string | undefined>;
45
- mode: string;
46
- }
47
- type FakewareConfigFn = (env: ConfigEnv) => FakewareUserConfig;
48
- declare function defineConfig(config: FakewareUserConfig): FakewareUserConfig;
49
- declare function defineConfig(config: FakewareConfigFn): FakewareConfigFn;
50
- //#endregion
51
- export { type ConfigEnv, type FakewareConfig, type FakewareConfigFn, type FakewareUserConfig, defineConfig, fakewareConfigSchema, mediaSchema, pluginRefSchema, shopwareSchema };
52
- //# sourceMappingURL=index.d.mts.map
1
+ import { a as interpolate, c as FakewareConfigFn, d as FakewareUserConfig, f as TransactionConfig, h as transactionSchema, i as loadConfig, l as defineConfig, m as shopwareSchema, n as LoadConfigOptions, o as ConfigError, p as fakewareConfigSchema, r as LoadedConfig, s as ConfigEnv, t as DEFAULT_CONFIG_FILENAME, u as FakewareConfig } from "../index-jYm7NShY.mjs";
2
+ export { type ConfigEnv, ConfigError, DEFAULT_CONFIG_FILENAME, type FakewareConfig, type FakewareConfigFn, type FakewareUserConfig, type LoadConfigOptions, type LoadedConfig, type TransactionConfig, defineConfig, fakewareConfigSchema, interpolate, loadConfig, shopwareSchema, transactionSchema };
@@ -1,36 +1,2 @@
1
- import { z } from "zod";
2
- //#region src/config/define.ts
3
- function defineConfig(config) {
4
- return config;
5
- }
6
- //#endregion
7
- //#region src/config/schema.ts
8
- const shopwareSchema = z.object({
9
- url: z.string().min(1, "shopware.url is required"),
10
- clientId: z.string().min(1, "shopware.clientId is required"),
11
- clientSecret: z.string().min(1, "shopware.clientSecret is required")
12
- });
13
- const mediaSchema = z.object({
14
- provider: z.string(),
15
- perProduct: z.object({
16
- min: z.number().int().nonnegative(),
17
- max: z.number().int().nonnegative()
18
- }).optional()
19
- });
20
- const pluginRefSchema = z.union([z.string(), z.tuple([z.string(), z.record(z.string(), z.unknown())])]);
21
- const fakewareConfigSchema = z.object({
22
- extends: z.union([z.string(), z.array(z.string())]).optional(),
23
- shopware: shopwareSchema.optional(),
24
- locale: z.string().optional(),
25
- seed: z.string().optional(),
26
- batchSize: z.number().int().positive().default(100),
27
- generators: z.record(z.string(), z.unknown()).default({}),
28
- media: mediaSchema.optional(),
29
- scenario: z.string().optional(),
30
- scenarios: z.record(z.string(), z.unknown()).default({}),
31
- plugins: z.array(pluginRefSchema).default([])
32
- });
33
- //#endregion
34
- export { defineConfig, fakewareConfigSchema, mediaSchema, pluginRefSchema, shopwareSchema };
35
-
36
- //# sourceMappingURL=index.mjs.map
1
+ import { a as transactionSchema, c as defineConfig, i as shopwareSchema, n as loadConfig, o as interpolate, r as fakewareConfigSchema, s as ConfigError, t as DEFAULT_CONFIG_FILENAME } from "../config-DGneBZWH.mjs";
2
+ export { ConfigError, DEFAULT_CONFIG_FILENAME, defineConfig, fakewareConfigSchema, interpolate, loadConfig, shopwareSchema, transactionSchema };
@@ -0,0 +1,133 @@
1
+ import { access, readFile } from "node:fs/promises";
2
+ import { dirname, isAbsolute, join, resolve } from "node:path";
3
+ import { createJiti } from "jiti";
4
+ import { z } from "zod";
5
+ //#region src/runtime/load-module.ts
6
+ var LoadModuleError = class extends Error {};
7
+ const jiti = createJiti(import.meta.url);
8
+ async function loadModule(absPath) {
9
+ try {
10
+ return await jiti.import(absPath);
11
+ } catch (error) {
12
+ throw new LoadModuleError(`Could not load ${absPath}: ${error instanceof Error ? error.message : String(error)}`);
13
+ }
14
+ }
15
+ //#endregion
16
+ //#region src/config/define.ts
17
+ function defineConfig(config) {
18
+ return config;
19
+ }
20
+ //#endregion
21
+ //#region src/config/errors.ts
22
+ var ConfigError = class extends Error {};
23
+ //#endregion
24
+ //#region src/config/interpolate.ts
25
+ const ENV_REF = /^\$([A-Z0-9_]+)$/;
26
+ function interpolate(value, env) {
27
+ if (typeof value === "string") {
28
+ const match = ENV_REF.exec(value);
29
+ if (!match) return value;
30
+ const name = match[1];
31
+ const resolved = env[name];
32
+ if (resolved === void 0) throw new ConfigError(`Config references $${name}, but it is not set (check your .env).`);
33
+ return resolved;
34
+ }
35
+ if (Array.isArray(value)) return value.map((item) => interpolate(item, env));
36
+ if (value && typeof value === "object") {
37
+ const out = {};
38
+ for (const [k, v] of Object.entries(value)) out[k] = interpolate(v, env);
39
+ return out;
40
+ }
41
+ return value;
42
+ }
43
+ //#endregion
44
+ //#region src/config/schema.ts
45
+ const shopwareSchema = z.object({
46
+ url: z.string().min(1, "shopware.url is required"),
47
+ clientId: z.string().min(1, "shopware.clientId is required"),
48
+ clientSecret: z.string().min(1, "shopware.clientSecret is required")
49
+ });
50
+ const transactionSchema = z.object({
51
+ onError: z.enum([
52
+ "rollback",
53
+ "continue",
54
+ "stop"
55
+ ]).default("rollback"),
56
+ atomic: z.boolean().default(true)
57
+ });
58
+ const fakewareConfigSchema = z.object({
59
+ shopware: shopwareSchema.optional(),
60
+ transaction: transactionSchema.prefault({})
61
+ });
62
+ //#endregion
63
+ //#region src/config/load.ts
64
+ const DEFAULT_CONFIG_FILENAME = "fakeware.config.ts";
65
+ async function fileExists(path) {
66
+ try {
67
+ await access(path);
68
+ return true;
69
+ } catch {
70
+ return false;
71
+ }
72
+ }
73
+ async function findConfig(cwd) {
74
+ let dir = cwd;
75
+ for (;;) {
76
+ const candidate = join(dir, DEFAULT_CONFIG_FILENAME);
77
+ if (await fileExists(candidate)) return candidate;
78
+ const parent = dirname(dir);
79
+ if (parent === dir) break;
80
+ dir = parent;
81
+ }
82
+ throw new ConfigError(`No ${DEFAULT_CONFIG_FILENAME} found in ${cwd} or any parent directory. Run \`fakeware init\` first.`);
83
+ }
84
+ async function readEnvFile(projectRoot) {
85
+ const path = join(projectRoot, ".env");
86
+ if (!await fileExists(path)) return {};
87
+ const out = {};
88
+ const contents = await readFile(path, "utf8");
89
+ for (const raw of contents.split("\n")) {
90
+ const line = raw.trim();
91
+ if (!line || line.startsWith("#")) continue;
92
+ const eq = line.indexOf("=");
93
+ if (eq === -1) continue;
94
+ const key = line.slice(0, eq).trim();
95
+ let val = line.slice(eq + 1).trim();
96
+ if (val.startsWith("\"") && val.endsWith("\"") || val.startsWith("'") && val.endsWith("'")) val = val.slice(1, -1);
97
+ out[key] = val;
98
+ }
99
+ return out;
100
+ }
101
+ function isConfigFn(value) {
102
+ return typeof value === "function";
103
+ }
104
+ async function loadConfig(opts = {}) {
105
+ const cwd = opts.cwd ?? process.cwd();
106
+ const configPath = opts.configFile ? isAbsolute(opts.configFile) ? opts.configFile : resolve(cwd, opts.configFile) : await findConfig(cwd);
107
+ const projectRoot = dirname(configPath);
108
+ const env = {
109
+ ...process.env,
110
+ ...await readEnvFile(projectRoot)
111
+ };
112
+ const exported = (await loadModule(configPath)).default;
113
+ if (exported === void 0) throw new ConfigError(`${configPath} must \`export default defineConfig(...)\`.`);
114
+ const configEnv = {
115
+ env,
116
+ mode: opts.mode ?? "development"
117
+ };
118
+ const interpolated = interpolate(isConfigFn(exported) ? exported(configEnv) : exported, env);
119
+ const parsed = fakewareConfigSchema.safeParse(interpolated);
120
+ if (!parsed.success) throw new ConfigError(`Invalid config in ${configPath}: ${parsed.error.message}`);
121
+ const { shopware } = parsed.data;
122
+ if (!shopware) throw new ConfigError(`No \`shopware\` connection configured in ${configPath}. up/down need a shop to talk to.`);
123
+ return {
124
+ config: parsed.data,
125
+ connection: shopware,
126
+ configPath,
127
+ projectRoot
128
+ };
129
+ }
130
+ //#endregion
131
+ export { transactionSchema as a, defineConfig as c, shopwareSchema as i, LoadModuleError as l, loadConfig as n, interpolate as o, fakewareConfigSchema as r, ConfigError as s, DEFAULT_CONFIG_FILENAME as t, loadModule as u };
132
+
133
+ //# sourceMappingURL=config-DGneBZWH.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config-DGneBZWH.mjs","names":[],"sources":["../src/runtime/load-module.ts","../src/config/define.ts","../src/config/errors.ts","../src/config/interpolate.ts","../src/config/schema.ts","../src/config/load.ts"],"sourcesContent":["import { createJiti } from 'jiti'\n\nexport class LoadModuleError extends Error {}\n\nconst jiti = createJiti(import.meta.url)\n\nexport async function loadModule<T = unknown>(absPath: string): Promise<T> {\n try {\n return (await jiti.import(absPath)) as T\n } catch (error) {\n throw new LoadModuleError(\n `Could not load ${absPath}: ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n}\n","import type { FakewareUserConfig } from './schema'\n\nexport interface ConfigEnv {\n env: Record<string, string | undefined>\n mode: string\n}\n\nexport type FakewareConfigFn = (env: ConfigEnv) => FakewareUserConfig\n\nexport function defineConfig(config: FakewareUserConfig): FakewareUserConfig\nexport function defineConfig(config: FakewareConfigFn): FakewareConfigFn\nexport function defineConfig(\n config: FakewareUserConfig | FakewareConfigFn,\n): FakewareUserConfig | FakewareConfigFn {\n return config\n}\n","export class ConfigError extends Error {}\n","import { ConfigError } from './errors'\n\nconst ENV_REF = /^\\$([A-Z0-9_]+)$/\n\nexport function interpolate<T>(value: T, env: Record<string, string | undefined>): T {\n if (typeof value === 'string') {\n const match = ENV_REF.exec(value)\n if (!match) return value\n const name = match[1] as string\n const resolved = env[name]\n if (resolved === undefined) {\n throw new ConfigError(`Config references $${name}, but it is not set (check your .env).`)\n }\n return resolved as unknown as T\n }\n if (Array.isArray(value)) {\n return value.map((item) => interpolate(item, env)) as unknown as T\n }\n if (value && typeof value === 'object') {\n const out: Record<string, unknown> = {}\n for (const [k, v] of Object.entries(value)) {\n out[k] = interpolate(v, env)\n }\n return out as T\n }\n return value\n}\n","import { z } from 'zod'\n\nexport const shopwareSchema = z.object({\n url: z.string().min(1, 'shopware.url is required'),\n clientId: z.string().min(1, 'shopware.clientId is required'),\n clientSecret: z.string().min(1, 'shopware.clientSecret is required'),\n})\n\nexport const transactionSchema = z.object({\n onError: z.enum(['rollback', 'continue', 'stop']).default('rollback'),\n atomic: z.boolean().default(true),\n})\n\nexport const fakewareConfigSchema = z.object({\n shopware: shopwareSchema.optional(),\n transaction: transactionSchema.prefault({}),\n})\n\nexport type TransactionConfig = z.output<typeof transactionSchema>\n\nexport type FakewareConfig = z.output<typeof fakewareConfigSchema>\n\nexport type FakewareUserConfig = z.input<typeof fakewareConfigSchema>\n","import { access, readFile } from 'node:fs/promises'\nimport { dirname, isAbsolute, join, resolve } from 'node:path'\nimport { loadModule } from '../runtime'\nimport type { ShopwareConnection } from '../shopware'\nimport type { ConfigEnv, FakewareConfigFn } from './define'\nimport { ConfigError } from './errors'\nimport { interpolate } from './interpolate'\nimport { type FakewareConfig, type FakewareUserConfig, fakewareConfigSchema } from './schema'\n\nexport const DEFAULT_CONFIG_FILENAME = 'fakeware.config.ts'\n\nexport interface LoadConfigOptions {\n cwd?: string\n configFile?: string\n mode?: string\n}\n\nexport interface LoadedConfig {\n config: FakewareConfig\n connection: ShopwareConnection\n configPath: string\n projectRoot: string\n}\n\nasync function fileExists(path: string): Promise<boolean> {\n try {\n await access(path)\n return true\n } catch {\n return false\n }\n}\n\nasync function findConfig(cwd: string): Promise<string> {\n let dir = cwd\n for (;;) {\n const candidate = join(dir, DEFAULT_CONFIG_FILENAME)\n if (await fileExists(candidate)) return candidate\n const parent = dirname(dir)\n if (parent === dir) break\n dir = parent\n }\n throw new ConfigError(\n `No ${DEFAULT_CONFIG_FILENAME} found in ${cwd} or any parent directory. Run \\`fakeware init\\` first.`,\n )\n}\n\nasync function readEnvFile(projectRoot: string): Promise<Record<string, string>> {\n const path = join(projectRoot, '.env')\n if (!(await fileExists(path))) return {}\n const out: Record<string, string> = {}\n const contents = await readFile(path, 'utf8')\n for (const raw of contents.split('\\n')) {\n const line = raw.trim()\n if (!line || line.startsWith('#')) continue\n const eq = line.indexOf('=')\n if (eq === -1) continue\n const key = line.slice(0, eq).trim()\n let val = line.slice(eq + 1).trim()\n if ((val.startsWith('\"') && val.endsWith('\"')) || (val.startsWith(\"'\") && val.endsWith(\"'\"))) {\n val = val.slice(1, -1)\n }\n out[key] = val\n }\n return out\n}\n\nfunction isConfigFn(value: unknown): value is FakewareConfigFn {\n return typeof value === 'function'\n}\n\nexport async function loadConfig(opts: LoadConfigOptions = {}): Promise<LoadedConfig> {\n const cwd = opts.cwd ?? process.cwd()\n const configPath = opts.configFile\n ? isAbsolute(opts.configFile)\n ? opts.configFile\n : resolve(cwd, opts.configFile)\n : await findConfig(cwd)\n const projectRoot = dirname(configPath)\n\n const env: Record<string, string | undefined> = {\n ...process.env,\n ...(await readEnvFile(projectRoot)),\n }\n\n const mod = await loadModule<{ default?: unknown }>(configPath)\n const exported = mod.default\n if (exported === undefined) {\n throw new ConfigError(`${configPath} must \\`export default defineConfig(...)\\`.`)\n }\n\n const configEnv: ConfigEnv = { env, mode: opts.mode ?? 'development' }\n const raw = isConfigFn(exported) ? exported(configEnv) : (exported as FakewareUserConfig)\n\n const interpolated = interpolate(raw, env)\n\n const parsed = fakewareConfigSchema.safeParse(interpolated)\n if (!parsed.success) {\n throw new ConfigError(`Invalid config in ${configPath}: ${parsed.error.message}`)\n }\n\n const { shopware } = parsed.data\n if (!shopware) {\n throw new ConfigError(\n `No \\`shopware\\` connection configured in ${configPath}. up/down need a shop to talk to.`,\n )\n }\n\n return { config: parsed.data, connection: shopware, configPath, projectRoot }\n}\n"],"mappings":";;;;;AAEA,IAAa,kBAAb,cAAqC,MAAM,CAAC;AAE5C,MAAM,OAAO,WAAW,OAAO,KAAK,GAAG;AAEvC,eAAsB,WAAwB,SAA6B;CACzE,IAAI;EACF,OAAQ,MAAM,KAAK,OAAO,OAAO;CACnC,SAAS,OAAO;EACd,MAAM,IAAI,gBACR,kBAAkB,QAAQ,IAAI,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,GACrF;CACF;AACF;;;ACHA,SAAgB,aACd,QACuC;CACvC,OAAO;AACT;;;ACfA,IAAa,cAAb,cAAiC,MAAM,CAAC;;;ACExC,MAAM,UAAU;AAEhB,SAAgB,YAAe,OAAU,KAA4C;CACnF,IAAI,OAAO,UAAU,UAAU;EAC7B,MAAM,QAAQ,QAA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AAM,IAAI,YAAY,GAAG,WAAW,4CAA4C;CAGlF,MAAM,YAAuB;EAAE;EAAK,MAAM,KAAK,QAAQ;CAAc;CAGrE,MAAM,eAAe,YAFT,WAAW,QAAQ,IAAI,SAAS,SAAS,IAAK,UAEpB,GAAG;CAEzC,MAAM,SAAS,qBAAqB,UAAU,YAAY;CAC1D,IAAI,CAAC,OAAO,SACV,MAAM,IAAI,YAAY,qBAAqB,WAAW,IAAI,OAAO,MAAM,SAAS;CAGlF,MAAM,EAAE,aAAa,OAAO;CAC5B,IAAI,CAAC,UACH,MAAM,IAAI,YACR,4CAA4C,WAAW,kCACzD;CAGF,OAAO;EAAE,QAAQ,OAAO;EAAM,YAAY;EAAU;EAAY;CAAY;AAC9E"}
@@ -0,0 +1,62 @@
1
+ import { createAdminAPIClient } from "@shopware/api-client";
2
+ import { operations } from "@shopware/api-client/admin-api-types";
3
+
4
+ //#region src/shopware/types.d.ts
5
+ interface ShopwareConnection {
6
+ url: string;
7
+ clientId: string;
8
+ clientSecret: string;
9
+ }
10
+ interface ShopInfo {
11
+ locales: string[];
12
+ defaultLocale: string;
13
+ }
14
+ //#endregion
15
+ //#region src/shopware/client.d.ts
16
+ type ShopwareClient = ReturnType<typeof createAdminAPIClient<operations>>;
17
+ declare function createShopwareClient(connection: ShopwareConnection): ShopwareClient;
18
+ //#endregion
19
+ //#region src/shopware/errors.d.ts
20
+ declare class ShopwareConnectionError extends Error {}
21
+ //#endregion
22
+ //#region src/shopware/operations.d.ts
23
+ declare function toConnectionError(connection: ShopwareConnection, error: unknown): ShopwareConnectionError;
24
+ declare function validateConnection(connection: ShopwareConnection): Promise<void>;
25
+ declare function fetchShopInfo(connection: ShopwareConnection): Promise<ShopInfo>;
26
+ //#endregion
27
+ //#region src/domain/sink.d.ts
28
+ type SinkRecord = Record<string, unknown> & {
29
+ id: string;
30
+ };
31
+ type SyncOperation = {
32
+ entity: string;
33
+ action: 'upsert';
34
+ records: SinkRecord[];
35
+ } | {
36
+ entity: string;
37
+ action: 'delete';
38
+ ids: string[];
39
+ };
40
+ interface BatchProgress {
41
+ records: number;
42
+ recordsTotal: number;
43
+ batches: number;
44
+ batchesTotal: number;
45
+ }
46
+ type OnBatch = (progress: BatchProgress) => void;
47
+ interface ShopwareSink {
48
+ upsert(entity: string, records: SinkRecord[], onBatch?: OnBatch): Promise<void>;
49
+ delete(entity: string, ids: string[], onBatch?: OnBatch): Promise<void>;
50
+ applyAtomic(operations: SyncOperation[]): Promise<void>;
51
+ }
52
+ //#endregion
53
+ //#region src/shopware/sink.d.ts
54
+ interface SyncSinkOptions {
55
+ client?: ShopwareClient;
56
+ }
57
+ declare const ATOMIC_REQUEST_BYTE_LIMIT: number;
58
+ declare function estimateSyncBytes(operations: SyncOperation[]): number;
59
+ declare function createSyncSink(connection: ShopwareConnection, options?: SyncSinkOptions): ShopwareSink;
60
+ //#endregion
61
+ export { ShopwareSink as a, fetchShopInfo as c, ShopwareConnectionError as d, ShopwareClient as f, ShopwareConnection as h, BatchProgress as i, toConnectionError as l, ShopInfo as m, createSyncSink as n, SinkRecord as o, createShopwareClient as p, estimateSyncBytes as r, SyncOperation as s, ATOMIC_REQUEST_BYTE_LIMIT as t, validateConnection as u };
62
+ //# sourceMappingURL=index-Brciwig_.d.mts.map
@@ -0,0 +1,68 @@
1
+ import { h as ShopwareConnection } from "./index-Brciwig_.mjs";
2
+ import { z } from "zod";
3
+
4
+ //#region src/config/schema.d.ts
5
+ declare const shopwareSchema: z.ZodObject<{
6
+ url: z.ZodString;
7
+ clientId: z.ZodString;
8
+ clientSecret: z.ZodString;
9
+ }, z.core.$strip>;
10
+ declare const transactionSchema: z.ZodObject<{
11
+ onError: z.ZodDefault<z.ZodEnum<{
12
+ rollback: "rollback";
13
+ continue: "continue";
14
+ stop: "stop";
15
+ }>>;
16
+ atomic: z.ZodDefault<z.ZodBoolean>;
17
+ }, z.core.$strip>;
18
+ declare const fakewareConfigSchema: z.ZodObject<{
19
+ shopware: z.ZodOptional<z.ZodObject<{
20
+ url: z.ZodString;
21
+ clientId: z.ZodString;
22
+ clientSecret: z.ZodString;
23
+ }, z.core.$strip>>;
24
+ transaction: z.ZodPrefault<z.ZodObject<{
25
+ onError: z.ZodDefault<z.ZodEnum<{
26
+ rollback: "rollback";
27
+ continue: "continue";
28
+ stop: "stop";
29
+ }>>;
30
+ atomic: z.ZodDefault<z.ZodBoolean>;
31
+ }, z.core.$strip>>;
32
+ }, z.core.$strip>;
33
+ type TransactionConfig = z.output<typeof transactionSchema>;
34
+ type FakewareConfig = z.output<typeof fakewareConfigSchema>;
35
+ type FakewareUserConfig = z.input<typeof fakewareConfigSchema>;
36
+ //#endregion
37
+ //#region src/config/define.d.ts
38
+ interface ConfigEnv {
39
+ env: Record<string, string | undefined>;
40
+ mode: string;
41
+ }
42
+ type FakewareConfigFn = (env: ConfigEnv) => FakewareUserConfig;
43
+ declare function defineConfig(config: FakewareUserConfig): FakewareUserConfig;
44
+ declare function defineConfig(config: FakewareConfigFn): FakewareConfigFn;
45
+ //#endregion
46
+ //#region src/config/errors.d.ts
47
+ declare class ConfigError extends Error {}
48
+ //#endregion
49
+ //#region src/config/interpolate.d.ts
50
+ declare function interpolate<T>(value: T, env: Record<string, string | undefined>): T;
51
+ //#endregion
52
+ //#region src/config/load.d.ts
53
+ declare const DEFAULT_CONFIG_FILENAME = "fakeware.config.ts";
54
+ interface LoadConfigOptions {
55
+ cwd?: string;
56
+ configFile?: string;
57
+ mode?: string;
58
+ }
59
+ interface LoadedConfig {
60
+ config: FakewareConfig;
61
+ connection: ShopwareConnection;
62
+ configPath: string;
63
+ projectRoot: string;
64
+ }
65
+ declare function loadConfig(opts?: LoadConfigOptions): Promise<LoadedConfig>;
66
+ //#endregion
67
+ export { interpolate as a, FakewareConfigFn as c, FakewareUserConfig as d, TransactionConfig as f, transactionSchema as h, loadConfig as i, defineConfig as l, shopwareSchema as m, LoadConfigOptions as n, ConfigError as o, fakewareConfigSchema as p, LoadedConfig as r, ConfigEnv as s, DEFAULT_CONFIG_FILENAME as t, FakewareConfig as u };
68
+ //# sourceMappingURL=index-jYm7NShY.d.mts.map
@@ -0,0 +1,144 @@
1
+ import { r as LoadedConfig } from "./index-jYm7NShY.mjs";
2
+ import { a as ShopwareSink, i as BatchProgress, o as SinkRecord, s as SyncOperation } from "./index-Brciwig_.mjs";
3
+ import { Schemas } from "@shopware/api-client/admin-api-types";
4
+
5
+ //#region src/define/ctx.d.ts
6
+ interface Ctx {
7
+ index: number;
8
+ count: number;
9
+ ref(path: string): string;
10
+ refs(entity: string): string[];
11
+ }
12
+ //#endregion
13
+ //#region src/define/schema.d.ts
14
+ type Words<S extends string, Cur extends string = '', Acc extends string[] = []> = S extends `${infer H}${infer T}` ? H extends Uppercase<H> ? Cur extends '' ? Words<T, H, Acc> : Words<T, H, [...Acc, Cur]> : Words<T, `${Cur}${H}`, Acc> : Cur extends '' ? Acc : [...Acc, Cur];
15
+ type JoinSnake<T extends string[]> = T extends [infer A extends string, ...infer R extends string[]] ? R extends [] ? Lowercase<A> : `${Lowercase<A>}_${JoinSnake<R>}` : '';
16
+ type SnakeOfPascal<S extends string> = JoinSnake<Words<S>>;
17
+ type EntityKey = { [K in keyof Schemas]: K extends `${string}JsonApi` ? never : K extends Capitalize<K & string> ? Schemas[K] extends {
18
+ id?: string;
19
+ } ? K : never : never }[keyof Schemas] & string;
20
+ type EntityNameToKey = { [K in EntityKey as SnakeOfPascal<K>]: K };
21
+ type EntityName = keyof EntityNameToKey & string;
22
+ type SchemaOf<E extends EntityName> = Schemas[EntityNameToKey[E]];
23
+ type Equal<X, Y> = (<G>() => G extends X ? 1 : 2) extends (<G>() => G extends Y ? 1 : 2) ? true : false;
24
+ type IsWritable<T, K extends keyof T> = Equal<{ [Q in K]: T[K] }, { -readonly [Q in K]: T[K] }>;
25
+ type NoiseField = 'extensions' | 'translated' | 'customFields' | `${string}Ro`;
26
+ type WritableKeys<T> = { [K in keyof T]-?: K extends NoiseField ? never : IsWritable<T, K> extends true ? K : never }[keyof T];
27
+ type AssocObject<T> = ('id' extends keyof T ? {
28
+ id?: string;
29
+ } : object) & { [K in keyof T]?: unknown };
30
+ type AssocElement<U> = U extends object ? AssocObject<U> : U;
31
+ type Field<T> = T extends (infer U)[] ? Producible<AssocElement<U>>[] : T extends string | number | boolean | null ? T : T extends object ? AssocObject<T> : T;
32
+ type Producible<T> = Field<T> | ((ctx: Ctx) => Field<T>);
33
+ type RecordShape<E extends EntityName> = {
34
+ $key?: string;
35
+ } & { [K in WritableKeys<SchemaOf<E>>]?: Producible<SchemaOf<E>[K]> };
36
+ type DefineRecord<E extends EntityName> = RecordShape<E> | ((ctx: Ctx) => RecordShape<E>);
37
+ //#endregion
38
+ //#region src/define/define.d.ts
39
+ declare function define<const E extends EntityName>(entity: E, records: DefineRecord<E> | readonly DefineRecord<E>[]): void;
40
+ declare function many<R extends Record<string, unknown>>(n: number, fn: (ctx: Ctx) => R): R;
41
+ declare function ref(path: string): string;
42
+ declare function refs(entity: string): string[];
43
+ //#endregion
44
+ //#region src/define/errors.d.ts
45
+ declare class RefError extends Error {}
46
+ //#endregion
47
+ //#region src/engine/run.d.ts
48
+ interface Reporter {
49
+ onStart?(entity: string, records?: number): void;
50
+ onBatch?(progress: BatchProgress): void;
51
+ onStep?(step: ReportStep): void;
52
+ onTransactionStart?(info: {
53
+ mode: 'atomic' | 'saga';
54
+ }): void;
55
+ onCommit?(info: {
56
+ committed: number;
57
+ }): void;
58
+ onCompensate?(entity: string, count: number): void;
59
+ onCompensateFail?(entity: string): void;
60
+ onSkip?(info: {
61
+ entity: string;
62
+ error: unknown;
63
+ }): void;
64
+ onStop?(info: {
65
+ failedEntity: string;
66
+ error: unknown;
67
+ message: string;
68
+ }): void;
69
+ }
70
+ interface ReportStep {
71
+ entity: string;
72
+ created: number;
73
+ updated: number;
74
+ unchanged: number;
75
+ deleted: number;
76
+ }
77
+ type OnError = 'rollback' | 'continue' | 'stop';
78
+ interface TransactionOptions {
79
+ onError: OnError;
80
+ atomic: boolean;
81
+ }
82
+ interface RunOptions {
83
+ loaded: LoadedConfig;
84
+ sink: ShopwareSink;
85
+ dryRun?: boolean;
86
+ reporter?: Reporter;
87
+ fakewareVersion?: string;
88
+ now?: string;
89
+ transaction?: TransactionOptions;
90
+ }
91
+ interface UpResult {
92
+ steps: ReportStep[];
93
+ manifestWritten: boolean;
94
+ mode: 'atomic' | 'saga' | 'dry-run' | 'noop';
95
+ committed: number;
96
+ rolledBack: number;
97
+ }
98
+ interface DownResult {
99
+ steps: ReportStep[];
100
+ reverted: boolean;
101
+ }
102
+ declare function runUp(opts: RunOptions): Promise<UpResult>;
103
+ declare function runDown(opts: RunOptions): Promise<DownResult>;
104
+ //#endregion
105
+ //#region src/engine/errors.d.ts
106
+ declare class GraphError extends Error {}
107
+ declare class TransactionError extends Error {
108
+ readonly rolledBack: ReportStep[];
109
+ readonly failedEntity: string;
110
+ readonly unrevertableUpdates: boolean;
111
+ readonly compensationErrors: unknown[];
112
+ constructor(message: string, options: {
113
+ cause: unknown;
114
+ rolledBack: ReportStep[];
115
+ failedEntity: string;
116
+ unrevertableUpdates?: boolean;
117
+ compensationErrors?: unknown[];
118
+ });
119
+ }
120
+ //#endregion
121
+ //#region src/engine/manifest.d.ts
122
+ interface ManifestRecord {
123
+ id: string;
124
+ hash: string;
125
+ }
126
+ interface ManifestEntity {
127
+ entity: string;
128
+ records: ManifestRecord[];
129
+ }
130
+ interface Manifest {
131
+ version: 1;
132
+ fakewareVersion: string;
133
+ createdAt: string;
134
+ shopwareUrl: string;
135
+ entities: ManifestEntity[];
136
+ checksum: string;
137
+ }
138
+ declare function readManifest(projectRoot: string, shopwareUrl: string): Promise<Manifest | null>;
139
+ //#endregion
140
+ //#region src/runtime/load-module.d.ts
141
+ declare class LoadModuleError extends Error {}
142
+ //#endregion
143
+ export { type BatchProgress, type Ctx, type DefineRecord, type DownResult, type EntityName, GraphError, LoadModuleError, type Manifest, type ManifestEntity, type ManifestRecord, type OnError, RefError, type ReportStep, type Reporter, type RunOptions, type ShopwareSink, type SinkRecord, type SyncOperation, TransactionError, type TransactionOptions, type UpResult, define, many, readManifest, ref, refs, runDown, runUp };
144
+ //# sourceMappingURL=index.d.mts.map