@forgeax/engine-ddc 0.0.0-dev.8d955ade1c79

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.
Files changed (100) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +147 -0
  3. package/dist/.tsbuildinfo +1 -0
  4. package/dist/__tests__/concurrency.integration.test.d.ts +2 -0
  5. package/dist/__tests__/concurrency.integration.test.d.ts.map +1 -0
  6. package/dist/__tests__/consumer-path.integration.test.d.ts +2 -0
  7. package/dist/__tests__/consumer-path.integration.test.d.ts.map +1 -0
  8. package/dist/__tests__/crash-recovery.integration.test.d.ts +2 -0
  9. package/dist/__tests__/crash-recovery.integration.test.d.ts.map +1 -0
  10. package/dist/__tests__/entry-store.integration.test.d.ts +2 -0
  11. package/dist/__tests__/entry-store.integration.test.d.ts.map +1 -0
  12. package/dist/__tests__/errors.unit.test.d.ts +2 -0
  13. package/dist/__tests__/errors.unit.test.d.ts.map +1 -0
  14. package/dist/__tests__/generation-session.integration.test.d.ts +2 -0
  15. package/dist/__tests__/generation-session.integration.test.d.ts.map +1 -0
  16. package/dist/__tests__/generation-session.unit.test.d.ts +2 -0
  17. package/dist/__tests__/generation-session.unit.test.d.ts.map +1 -0
  18. package/dist/__tests__/key.unit.test.d.ts +2 -0
  19. package/dist/__tests__/key.unit.test.d.ts.map +1 -0
  20. package/dist/__tests__/layout.unit.test.d.ts +2 -0
  21. package/dist/__tests__/layout.unit.test.d.ts.map +1 -0
  22. package/dist/__tests__/lifecycle.unit.test.d.ts +2 -0
  23. package/dist/__tests__/lifecycle.unit.test.d.ts.map +1 -0
  24. package/dist/__tests__/multiprocess-gc.integration.test.d.ts +2 -0
  25. package/dist/__tests__/multiprocess-gc.integration.test.d.ts.map +1 -0
  26. package/dist/__tests__/multiprocess-lifecycle.integration.test.d.ts +2 -0
  27. package/dist/__tests__/multiprocess-lifecycle.integration.test.d.ts.map +1 -0
  28. package/dist/__tests__/multiprocess-worker.d.ts +2 -0
  29. package/dist/__tests__/multiprocess-worker.d.ts.map +1 -0
  30. package/dist/__tests__/owner-chain.integration.test.d.ts +2 -0
  31. package/dist/__tests__/owner-chain.integration.test.d.ts.map +1 -0
  32. package/dist/__tests__/status-root-kind-owner.test-d.d.ts +2 -0
  33. package/dist/__tests__/status-root-kind-owner.test-d.d.ts.map +1 -0
  34. package/dist/__tests__/status.unit.test.d.ts +2 -0
  35. package/dist/__tests__/status.unit.test.d.ts.map +1 -0
  36. package/dist/build-cache.d.ts +18 -0
  37. package/dist/build-cache.d.ts.map +1 -0
  38. package/dist/entry-store.d.ts +53 -0
  39. package/dist/entry-store.d.ts.map +1 -0
  40. package/dist/entry-store.mjs +349 -0
  41. package/dist/entry-store.mjs.map +1 -0
  42. package/dist/errors.d.ts +58 -0
  43. package/dist/errors.d.ts.map +1 -0
  44. package/dist/errors.mjs +109 -0
  45. package/dist/errors.mjs.map +1 -0
  46. package/dist/gc.d.ts +13 -0
  47. package/dist/gc.d.ts.map +1 -0
  48. package/dist/index.d.ts +12 -0
  49. package/dist/index.d.ts.map +1 -0
  50. package/dist/index.mjs +1574 -0
  51. package/dist/index.mjs.map +1 -0
  52. package/dist/key.d.ts +13 -0
  53. package/dist/key.d.ts.map +1 -0
  54. package/dist/key.mjs +38 -0
  55. package/dist/key.mjs.map +1 -0
  56. package/dist/layout.d.ts +51 -0
  57. package/dist/layout.d.ts.map +1 -0
  58. package/dist/layout.mjs +68 -0
  59. package/dist/layout.mjs.map +1 -0
  60. package/dist/lifecycle.d.ts +93 -0
  61. package/dist/lifecycle.d.ts.map +1 -0
  62. package/dist/publication.d.ts +50 -0
  63. package/dist/publication.d.ts.map +1 -0
  64. package/dist/runtime-scope.d.ts +10 -0
  65. package/dist/runtime-scope.d.ts.map +1 -0
  66. package/dist/session.d.ts +46 -0
  67. package/dist/session.d.ts.map +1 -0
  68. package/dist/status.d.ts +39 -0
  69. package/dist/status.d.ts.map +1 -0
  70. package/dist/status.mjs +20 -0
  71. package/dist/status.mjs.map +1 -0
  72. package/package.json +101 -0
  73. package/src/__tests__/concurrency.integration.test.ts +53 -0
  74. package/src/__tests__/consumer-path.integration.test.ts +61 -0
  75. package/src/__tests__/crash-recovery.integration.test.ts +84 -0
  76. package/src/__tests__/entry-store.integration.test.ts +83 -0
  77. package/src/__tests__/errors.unit.test.ts +54 -0
  78. package/src/__tests__/generation-session.integration.test.ts +202 -0
  79. package/src/__tests__/generation-session.unit.test.ts +35 -0
  80. package/src/__tests__/key.unit.test.ts +49 -0
  81. package/src/__tests__/layout.unit.test.ts +50 -0
  82. package/src/__tests__/lifecycle.unit.test.ts +258 -0
  83. package/src/__tests__/multiprocess-gc.integration.test.ts +36 -0
  84. package/src/__tests__/multiprocess-lifecycle.integration.test.ts +129 -0
  85. package/src/__tests__/multiprocess-worker.ts +41 -0
  86. package/src/__tests__/owner-chain.integration.test.ts +45 -0
  87. package/src/__tests__/status-root-kind-owner.test-d.ts +42 -0
  88. package/src/__tests__/status.unit.test.ts +56 -0
  89. package/src/build-cache.ts +60 -0
  90. package/src/entry-store.ts +317 -0
  91. package/src/errors.ts +164 -0
  92. package/src/gc.ts +34 -0
  93. package/src/index.ts +92 -0
  94. package/src/key.ts +46 -0
  95. package/src/layout.ts +132 -0
  96. package/src/lifecycle.ts +792 -0
  97. package/src/publication.ts +446 -0
  98. package/src/runtime-scope.ts +87 -0
  99. package/src/session.ts +281 -0
  100. package/src/status.ts +58 -0
package/src/layout.ts ADDED
@@ -0,0 +1,132 @@
1
+ import { isAbsolute, normalize } from 'node:path';
2
+
3
+ export const DDC_LAYOUT_VERSION = 'v2' as const;
4
+
5
+ export interface DdcBuildOptions {
6
+ readonly buildCacheRoot: string;
7
+ }
8
+
9
+ export interface DdcServeOptions extends DdcBuildOptions {
10
+ readonly projectDdcRoot?: string;
11
+ }
12
+
13
+ export interface DdcBuildLayout {
14
+ readonly objects: string;
15
+ readonly staging: string;
16
+ }
17
+
18
+ export interface DdcProjectLayout {
19
+ readonly root: string;
20
+ readonly scope: string;
21
+ readonly heads: string;
22
+ readonly generations: string;
23
+ readonly leases: string;
24
+ readonly staging: string;
25
+ }
26
+
27
+ export interface DdcLayout {
28
+ readonly version: typeof DDC_LAYOUT_VERSION;
29
+ readonly buildCacheRoot: string;
30
+ readonly projectDdcRoot: string;
31
+ readonly build: DdcBuildLayout;
32
+ readonly project: DdcProjectLayout;
33
+ }
34
+
35
+ export interface DdcBuildLayoutResult {
36
+ readonly ok: true;
37
+ readonly value: DdcBuildLayout;
38
+ }
39
+
40
+ export interface DdcLayoutError {
41
+ readonly code: 'ddc-project-root-required' | 'ddc-root-absolute-required';
42
+ readonly detail: string;
43
+ readonly hint: string;
44
+ readonly expected: string;
45
+ readonly actual?: string;
46
+ }
47
+
48
+ export interface DdcLayoutResult {
49
+ readonly ok: true;
50
+ readonly value: DdcLayout;
51
+ }
52
+
53
+ export interface DdcLayoutFailure {
54
+ readonly ok: false;
55
+ readonly error: DdcLayoutError;
56
+ }
57
+
58
+ type ClosedLayoutResult = DdcLayoutResult | DdcLayoutFailure;
59
+
60
+ function rootOrError(root: string, name: string): string | DdcLayoutError {
61
+ if (!isAbsolute(root)) {
62
+ return {
63
+ code: 'ddc-root-absolute-required',
64
+ detail: `${name} must be an absolute injected path`,
65
+ hint: `inject the canonical ${name} from the host root policy`,
66
+ expected: 'an absolute filesystem path',
67
+ actual: root,
68
+ };
69
+ }
70
+ const normalized = normalize(root);
71
+ return normalized.replace(/[\\/]+$/, '') || normalized;
72
+ }
73
+
74
+ function buildLayout(root: string): DdcBuildLayout {
75
+ return { objects: `${root}/objects`, staging: `${root}/staging` };
76
+ }
77
+
78
+ function projectLayout(root: string): DdcProjectLayout {
79
+ return {
80
+ root,
81
+ scope: `${root}/scope.json`,
82
+ heads: `${root}/heads`,
83
+ generations: `${root}/generations`,
84
+ leases: `${root}/leases`,
85
+ staging: `${root}/staging`,
86
+ };
87
+ }
88
+
89
+ export function resolveBuildDdcLayout(
90
+ options: DdcBuildOptions,
91
+ ): DdcBuildLayoutResult | DdcLayoutFailure {
92
+ const root = rootOrError(options.buildCacheRoot, 'buildCacheRoot');
93
+ return typeof root === 'string'
94
+ ? { ok: true, value: buildLayout(root) }
95
+ : { ok: false, error: root };
96
+ }
97
+
98
+ export function resolveDdcLayout(options: DdcServeOptions): ClosedLayoutResult {
99
+ const buildRoot = rootOrError(options.buildCacheRoot, 'buildCacheRoot');
100
+ if (typeof buildRoot !== 'string') return { ok: false, error: buildRoot };
101
+ if (options.projectDdcRoot === undefined || options.projectDdcRoot.trim().length === 0) {
102
+ return {
103
+ ok: false,
104
+ error: {
105
+ code: 'ddc-project-root-required',
106
+ detail: 'serve and publication require an explicitly injected projectDdcRoot',
107
+ hint: 'canonicalize the game directory in the host and inject its .forgeax/ddc/v2 root',
108
+ expected: 'projectDdcRoot',
109
+ },
110
+ };
111
+ }
112
+ const projectRoot = rootOrError(options.projectDdcRoot, 'projectDdcRoot');
113
+ if (typeof projectRoot !== 'string') return { ok: false, error: projectRoot };
114
+ return {
115
+ ok: true,
116
+ value: {
117
+ version: DDC_LAYOUT_VERSION,
118
+ buildCacheRoot: buildRoot,
119
+ projectDdcRoot: projectRoot,
120
+ build: buildLayout(buildRoot),
121
+ project: projectLayout(projectRoot),
122
+ },
123
+ };
124
+ }
125
+
126
+ export function isDdcLayout(value: unknown): value is DdcLayout {
127
+ return (
128
+ value !== null &&
129
+ typeof value === 'object' &&
130
+ (value as { readonly version?: unknown }).version === DDC_LAYOUT_VERSION
131
+ );
132
+ }