@spring-systems/core 0.8.6 → 0.8.9
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/dist/adapters/index.js +1 -56
- package/dist/auth/index.js +1 -19
- package/dist/chunk-3OMNT22N.js +1 -0
- package/dist/chunk-4KRUU6MS.js +1 -0
- package/dist/chunk-6J2VFOKL.js +1 -0
- package/dist/chunk-7P4BJDQR.js +1 -0
- package/dist/chunk-AMXSATFF.js +1 -0
- package/dist/chunk-BMIRKMVX.js +1 -0
- package/dist/chunk-EVDFSWPU.js +1 -0
- package/dist/chunk-F3VXVDPQ.js +1 -0
- package/dist/chunk-GSQE2NEY.js +1 -0
- package/dist/chunk-HUASNNWD.js +1 -0
- package/dist/chunk-ICKHSEIX.js +1 -0
- package/dist/chunk-JRHMAY5G.js +1 -0
- package/dist/chunk-MNLYYTGZ.js +7 -0
- package/dist/chunk-OOVZTF74.js +1 -0
- package/dist/chunk-PNDXLNCU.js +1 -0
- package/dist/chunk-R3XYEEGR.js +1 -0
- package/dist/chunk-RKLYBW3O.js +1 -0
- package/dist/chunk-RVQHSQYF.js +3 -0
- package/dist/chunk-UT6X6RQM.js +1 -0
- package/dist/chunk-Y6DB43IE.js +3 -0
- package/dist/chunk-YMSSF2ZU.js +1 -0
- package/dist/config/index.js +1 -109
- package/dist/devtools/index.js +1 -67
- package/dist/errors/index.js +1 -21
- package/dist/events/index.js +1 -12
- package/dist/i18n/index.js +1 -7
- package/dist/index.js +1 -42
- package/dist/instance/index.js +1 -37
- package/dist/logger/index.js +1 -27
- package/dist/middleware/index.js +1 -23
- package/dist/plugins/index.js +1 -16
- package/dist/testing/index.js +1 -171
- package/dist/types/index.js +1 -72
- package/dist/utils/index.d.ts +43 -1
- package/dist/utils/index.js +1 -772
- package/dist/validation/index.js +1 -147
- package/package.json +1 -1
- package/dist/adapters/index.js.map +0 -1
- package/dist/auth/index.js.map +0 -1
- package/dist/chunk-2PJWFA5S.js +0 -393
- package/dist/chunk-2PJWFA5S.js.map +0 -1
- package/dist/chunk-EFUBAQCV.js +0 -94
- package/dist/chunk-EFUBAQCV.js.map +0 -1
- package/dist/chunk-F2SIMWZ5.js +0 -173
- package/dist/chunk-F2SIMWZ5.js.map +0 -1
- package/dist/chunk-F7WUQJH7.js +0 -399
- package/dist/chunk-F7WUQJH7.js.map +0 -1
- package/dist/chunk-GON7Q32Q.js +0 -176
- package/dist/chunk-GON7Q32Q.js.map +0 -1
- package/dist/chunk-GXU75LQX.js +0 -182
- package/dist/chunk-GXU75LQX.js.map +0 -1
- package/dist/chunk-HFELOXDQ.js +0 -110
- package/dist/chunk-HFELOXDQ.js.map +0 -1
- package/dist/chunk-KX32MU3I.js +0 -190
- package/dist/chunk-KX32MU3I.js.map +0 -1
- package/dist/chunk-MEWPYTWC.js +0 -284
- package/dist/chunk-MEWPYTWC.js.map +0 -1
- package/dist/chunk-N2L4TUC4.js +0 -34
- package/dist/chunk-N2L4TUC4.js.map +0 -1
- package/dist/chunk-NQQIVCLX.js +0 -47
- package/dist/chunk-NQQIVCLX.js.map +0 -1
- package/dist/chunk-OSSX443T.js +0 -146
- package/dist/chunk-OSSX443T.js.map +0 -1
- package/dist/chunk-PT4DIYUK.js +0 -78
- package/dist/chunk-PT4DIYUK.js.map +0 -1
- package/dist/chunk-QAVWXARR.js +0 -51
- package/dist/chunk-QAVWXARR.js.map +0 -1
- package/dist/chunk-RRWKDFAB.js +0 -143
- package/dist/chunk-RRWKDFAB.js.map +0 -1
- package/dist/chunk-RUCXSQEY.js +0 -42
- package/dist/chunk-RUCXSQEY.js.map +0 -1
- package/dist/chunk-S6RPCN5H.js +0 -64
- package/dist/chunk-S6RPCN5H.js.map +0 -1
- package/dist/chunk-S7MKRNMI.js +0 -153
- package/dist/chunk-S7MKRNMI.js.map +0 -1
- package/dist/chunk-SQB4F3EF.js +0 -55
- package/dist/chunk-SQB4F3EF.js.map +0 -1
- package/dist/chunk-UDT2RPX2.js +0 -43
- package/dist/chunk-UDT2RPX2.js.map +0 -1
- package/dist/chunk-VRMVN2UM.js +0 -17
- package/dist/chunk-VRMVN2UM.js.map +0 -1
- package/dist/config/index.js.map +0 -1
- package/dist/devtools/index.js.map +0 -1
- package/dist/errors/index.js.map +0 -1
- package/dist/events/index.js.map +0 -1
- package/dist/i18n/index.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/instance/index.js.map +0 -1
- package/dist/logger/index.js.map +0 -1
- package/dist/middleware/index.js.map +0 -1
- package/dist/plugins/index.js.map +0 -1
- package/dist/testing/index.js.map +0 -1
- package/dist/types/index.js.map +0 -1
- package/dist/utils/index.js.map +0 -1
- package/dist/validation/index.js.map +0 -1
package/dist/chunk-EFUBAQCV.js
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
SpringConfigError
|
|
3
|
-
} from "./chunk-PT4DIYUK.js";
|
|
4
|
-
|
|
5
|
-
// src/utils/dev-warnings.ts
|
|
6
|
-
function isDevelopmentRuntime() {
|
|
7
|
-
const processNodeEnv = typeof process !== "undefined" ? process.env?.NODE_ENV : void 0;
|
|
8
|
-
if (typeof processNodeEnv === "string") {
|
|
9
|
-
return processNodeEnv !== "production";
|
|
10
|
-
}
|
|
11
|
-
const importMetaEnv = import.meta.env;
|
|
12
|
-
if (!importMetaEnv) {
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
if (importMetaEnv.DEV === true) return true;
|
|
16
|
-
if (importMetaEnv.PROD === true) return false;
|
|
17
|
-
if (typeof importMetaEnv.MODE === "string") return importMetaEnv.MODE !== "production";
|
|
18
|
-
if (typeof importMetaEnv.NODE_ENV === "string") return importMetaEnv.NODE_ENV !== "production";
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
var __DEV__ = isDevelopmentRuntime();
|
|
22
|
-
function devWarn(context, message) {
|
|
23
|
-
if (__DEV__) {
|
|
24
|
-
console.warn(`[${context}] ${message}`);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
function devThrow(context, message) {
|
|
28
|
-
const full = `[${context}] ${message}`;
|
|
29
|
-
if (__DEV__) {
|
|
30
|
-
throw new Error(full);
|
|
31
|
-
}
|
|
32
|
-
console.warn(full);
|
|
33
|
-
}
|
|
34
|
-
function devAssert(condition, context, message) {
|
|
35
|
-
if (__DEV__ && !condition) {
|
|
36
|
-
throw new Error(`[${context}] ${message}`);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// src/instance/current-instance.ts
|
|
41
|
-
var currentInstance = null;
|
|
42
|
-
function getAliveCurrentInstance() {
|
|
43
|
-
if (!currentInstance) return null;
|
|
44
|
-
if (currentInstance.state === "disposed") {
|
|
45
|
-
currentInstance = null;
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
return currentInstance;
|
|
49
|
-
}
|
|
50
|
-
function setSpringInstance(instance) {
|
|
51
|
-
const activeCurrent = getAliveCurrentInstance();
|
|
52
|
-
if (activeCurrent && activeCurrent !== instance) {
|
|
53
|
-
if (typeof window !== "undefined") {
|
|
54
|
-
devWarn(
|
|
55
|
-
"SpringInstance",
|
|
56
|
-
"Replacing an active SpringInstance. If you have multiple SpringProviders, ensure the previous one is unmounted before mounting a new one. For SSR, use React Context instead of the global singleton."
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
currentInstance = instance;
|
|
61
|
-
}
|
|
62
|
-
function getSpringInstance() {
|
|
63
|
-
const instance = getAliveCurrentInstance();
|
|
64
|
-
if (!instance) {
|
|
65
|
-
throw new SpringConfigError(
|
|
66
|
-
"SpringInstance not initialized. Ensure <SpringProvider> is mounted or call setSpringInstance() before accessing the instance."
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
return instance;
|
|
70
|
-
}
|
|
71
|
-
function tryGetSpringInstance() {
|
|
72
|
-
return getAliveCurrentInstance();
|
|
73
|
-
}
|
|
74
|
-
function clearSpringInstance() {
|
|
75
|
-
currentInstance = null;
|
|
76
|
-
}
|
|
77
|
-
function clearSpringInstanceIfCurrent(instance) {
|
|
78
|
-
if (currentInstance === instance) {
|
|
79
|
-
currentInstance = null;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export {
|
|
84
|
-
__DEV__,
|
|
85
|
-
devWarn,
|
|
86
|
-
devThrow,
|
|
87
|
-
devAssert,
|
|
88
|
-
setSpringInstance,
|
|
89
|
-
getSpringInstance,
|
|
90
|
-
tryGetSpringInstance,
|
|
91
|
-
clearSpringInstance,
|
|
92
|
-
clearSpringInstanceIfCurrent
|
|
93
|
-
};
|
|
94
|
-
//# sourceMappingURL=chunk-EFUBAQCV.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/dev-warnings.ts","../src/instance/current-instance.ts"],"sourcesContent":["/**\n * Dev-mode validation helpers.\n * In development: throws errors / logs warnings for invalid usage.\n * In production: silent (no runtime cost beyond a single boolean check).\n * @module dev-warnings\n */\n\nfunction isDevelopmentRuntime(): boolean {\n const processNodeEnv = typeof process !== \"undefined\" ? process.env?.NODE_ENV : undefined;\n if (typeof processNodeEnv === \"string\") {\n return processNodeEnv !== \"production\";\n }\n\n const importMetaEnv = (import.meta as ImportMeta & { env?: Record<string, unknown> }).env;\n if (!importMetaEnv) {\n return false;\n }\n\n if (importMetaEnv.DEV === true) return true;\n if (importMetaEnv.PROD === true) return false;\n if (typeof importMetaEnv.MODE === \"string\") return importMetaEnv.MODE !== \"production\";\n if (typeof importMetaEnv.NODE_ENV === \"string\") return importMetaEnv.NODE_ENV !== \"production\";\n\n return false;\n}\n\nconst __DEV__ = isDevelopmentRuntime();\n\n/**\n * Log a warning in development mode only.\n * No-op in production.\n */\nexport function devWarn(context: string, message: string): void {\n if (__DEV__) {\n console.warn(`[${context}] ${message}`);\n }\n}\n\n/**\n * Throw an error in development mode, log a warning in production.\n * Use for invalid API usage that should be caught during development.\n */\nexport function devThrow(context: string, message: string): void {\n const full = `[${context}] ${message}`;\n if (__DEV__) {\n throw new Error(full);\n }\n console.warn(full);\n}\n\n/**\n * Assert a condition in development mode.\n * Throws if condition is false in dev, no-op in production.\n */\nexport function devAssert(condition: boolean, context: string, message: string): void {\n if (__DEV__ && !condition) {\n throw new Error(`[${context}] ${message}`);\n }\n}\n\nexport { __DEV__ };\n","/**\n * Current instance bridge — the one remaining singleton.\n * Imperative code (API calls, middleware, etc.) reads from getSpringInstance().\n * The SpringProvider in ui sets this via setSpringInstance().\n *\n * **SSR safety note:** This module uses a module-level variable, which means\n * concurrent SSR requests in the same Node.js process will share the same\n * instance. For multi-tenant SSR, use React Context instead of getSpringInstance().\n *\n * @module current-instance\n */\n\nimport { SpringConfigError } from \"../errors/errors\";\nimport { devWarn } from \"../utils/dev-warnings\";\nimport type { SpringInstance } from \"./spring-instance\";\n\nlet currentInstance: SpringInstance | null = null;\n\nfunction getAliveCurrentInstance(): SpringInstance | null {\n if (!currentInstance) return null;\n if (currentInstance.state === \"disposed\") {\n currentInstance = null;\n return null;\n }\n return currentInstance;\n}\n\n/**\n * Set the current SpringInstance. Called once by SpringProvider on mount.\n * Warns if replacing an active (non-disposed) instance — this indicates\n * either multiple SpringProviders or missing cleanup.\n */\nexport function setSpringInstance(instance: SpringInstance): void {\n const activeCurrent = getAliveCurrentInstance();\n if (activeCurrent && activeCurrent !== instance) {\n // During SSR (no `window`), the module singleton persists between requests\n // because useEffect cleanup doesn't run server-side. Only warn on the client\n // where multiple simultaneous SpringProviders indicate a real problem.\n if (typeof window !== \"undefined\") {\n devWarn(\n \"SpringInstance\",\n \"Replacing an active SpringInstance. If you have multiple SpringProviders, \" +\n \"ensure the previous one is unmounted before mounting a new one. \" +\n \"For SSR, use React Context instead of the global singleton.\",\n );\n }\n }\n currentInstance = instance;\n}\n\n/**\n * Get the current SpringInstance. Throws if not set.\n * Use this in imperative code that requires a live instance.\n */\nexport function getSpringInstance(): SpringInstance {\n const instance = getAliveCurrentInstance();\n if (!instance) {\n throw new SpringConfigError(\n \"SpringInstance not initialized. Ensure <SpringProvider> is mounted or call setSpringInstance() before accessing the instance.\",\n );\n }\n return instance;\n}\n\n/**\n * Get the current SpringInstance or null if not yet initialized.\n * Use this in code that may run before SpringProvider mounts (e.g. config setup).\n */\nexport function tryGetSpringInstance(): SpringInstance | null {\n return getAliveCurrentInstance();\n}\n\n/**\n * Clear the current instance. For testing and cleanup only.\n */\nexport function clearSpringInstance(): void {\n currentInstance = null;\n}\n\n/**\n * Clear the current instance only if it matches the provided reference.\n * Prevents disposing an old instance from clearing a newer mounted instance.\n */\nexport function clearSpringInstanceIfCurrent(instance: SpringInstance): void {\n if (currentInstance === instance) {\n currentInstance = null;\n }\n}\n"],"mappings":";;;;;AAOA,SAAS,uBAAgC;AACrC,QAAM,iBAAiB,OAAO,YAAY,cAAc,QAAQ,KAAK,WAAW;AAChF,MAAI,OAAO,mBAAmB,UAAU;AACpC,WAAO,mBAAmB;AAAA,EAC9B;AAEA,QAAM,gBAAiB,YAA+D;AACtF,MAAI,CAAC,eAAe;AAChB,WAAO;AAAA,EACX;AAEA,MAAI,cAAc,QAAQ,KAAM,QAAO;AACvC,MAAI,cAAc,SAAS,KAAM,QAAO;AACxC,MAAI,OAAO,cAAc,SAAS,SAAU,QAAO,cAAc,SAAS;AAC1E,MAAI,OAAO,cAAc,aAAa,SAAU,QAAO,cAAc,aAAa;AAElF,SAAO;AACX;AAEA,IAAM,UAAU,qBAAqB;AAM9B,SAAS,QAAQ,SAAiB,SAAuB;AAC5D,MAAI,SAAS;AACT,YAAQ,KAAK,IAAI,OAAO,KAAK,OAAO,EAAE;AAAA,EAC1C;AACJ;AAMO,SAAS,SAAS,SAAiB,SAAuB;AAC7D,QAAM,OAAO,IAAI,OAAO,KAAK,OAAO;AACpC,MAAI,SAAS;AACT,UAAM,IAAI,MAAM,IAAI;AAAA,EACxB;AACA,UAAQ,KAAK,IAAI;AACrB;AAMO,SAAS,UAAU,WAAoB,SAAiB,SAAuB;AAClF,MAAI,WAAW,CAAC,WAAW;AACvB,UAAM,IAAI,MAAM,IAAI,OAAO,KAAK,OAAO,EAAE;AAAA,EAC7C;AACJ;;;AC1CA,IAAI,kBAAyC;AAE7C,SAAS,0BAAiD;AACtD,MAAI,CAAC,gBAAiB,QAAO;AAC7B,MAAI,gBAAgB,UAAU,YAAY;AACtC,sBAAkB;AAClB,WAAO;AAAA,EACX;AACA,SAAO;AACX;AAOO,SAAS,kBAAkB,UAAgC;AAC9D,QAAM,gBAAgB,wBAAwB;AAC9C,MAAI,iBAAiB,kBAAkB,UAAU;AAI7C,QAAI,OAAO,WAAW,aAAa;AAC/B;AAAA,QACI;AAAA,QACA;AAAA,MAGJ;AAAA,IACJ;AAAA,EACJ;AACA,oBAAkB;AACtB;AAMO,SAAS,oBAAoC;AAChD,QAAM,WAAW,wBAAwB;AACzC,MAAI,CAAC,UAAU;AACX,UAAM,IAAI;AAAA,MACN;AAAA,IACJ;AAAA,EACJ;AACA,SAAO;AACX;AAMO,SAAS,uBAA8C;AAC1D,SAAO,wBAAwB;AACnC;AAKO,SAAS,sBAA4B;AACxC,oBAAkB;AACtB;AAMO,SAAS,6BAA6B,UAAgC;AACzE,MAAI,oBAAoB,UAAU;AAC9B,sBAAkB;AAAA,EACtB;AACJ;","names":[]}
|
package/dist/chunk-F2SIMWZ5.js
DELETED
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
disposePlugins
|
|
3
|
-
} from "./chunk-GXU75LQX.js";
|
|
4
|
-
import {
|
|
5
|
-
createFrameworkConfig,
|
|
6
|
-
validateFrameworkConfig
|
|
7
|
-
} from "./chunk-F7WUQJH7.js";
|
|
8
|
-
import {
|
|
9
|
-
DEFAULT_MESSAGES
|
|
10
|
-
} from "./chunk-N2L4TUC4.js";
|
|
11
|
-
import {
|
|
12
|
-
sanitizeSecurityData
|
|
13
|
-
} from "./chunk-KX32MU3I.js";
|
|
14
|
-
import {
|
|
15
|
-
__DEV__,
|
|
16
|
-
clearSpringInstanceIfCurrent
|
|
17
|
-
} from "./chunk-EFUBAQCV.js";
|
|
18
|
-
import {
|
|
19
|
-
SpringConfigError
|
|
20
|
-
} from "./chunk-PT4DIYUK.js";
|
|
21
|
-
|
|
22
|
-
// src/instance/create-instance.ts
|
|
23
|
-
var instanceCounter = 0;
|
|
24
|
-
function logNotification(level, message) {
|
|
25
|
-
if (!__DEV__) return;
|
|
26
|
-
const prefix = "[Notification]";
|
|
27
|
-
if (level === "error") {
|
|
28
|
-
console.error(prefix, message);
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
if (level === "warn") {
|
|
32
|
-
console.warn(prefix, message);
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
console.info(prefix, message);
|
|
36
|
-
}
|
|
37
|
-
function createDefaultCoreState(overrides) {
|
|
38
|
-
const config = createFrameworkConfig(overrides);
|
|
39
|
-
return {
|
|
40
|
-
config,
|
|
41
|
-
contentAdapter: { getRes: (key) => DEFAULT_MESSAGES[key] ?? `[${key}]` },
|
|
42
|
-
notificationAdapter: {
|
|
43
|
-
error: (msg) => logNotification("error", msg),
|
|
44
|
-
success: (msg) => logNotification("info", msg),
|
|
45
|
-
warning: (msg) => logNotification("warn", msg),
|
|
46
|
-
info: (msg) => logNotification("info", msg)
|
|
47
|
-
},
|
|
48
|
-
logAdapter: {
|
|
49
|
-
onSecurityEvent: (event, data) => {
|
|
50
|
-
if (!__DEV__) {
|
|
51
|
-
console.warn(`[SPRING Security] ${event}`);
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
console.warn(`[SPRING Security] ${event}`, sanitizeSecurityData(data));
|
|
55
|
-
}
|
|
56
|
-
},
|
|
57
|
-
logoutHandler: null,
|
|
58
|
-
authenticated: false,
|
|
59
|
-
logoutInFlight: null,
|
|
60
|
-
eventListeners: /* @__PURE__ */ new Map(),
|
|
61
|
-
middlewareRegistry: /* @__PURE__ */ new Map(),
|
|
62
|
-
validatorRegistry: /* @__PURE__ */ new Map()
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
function createDefaultApiState() {
|
|
66
|
-
return {
|
|
67
|
-
authToken: null,
|
|
68
|
-
requestControllers: /* @__PURE__ */ new Set(),
|
|
69
|
-
requestHook: null,
|
|
70
|
-
responseHook: null,
|
|
71
|
-
apiPrefix: "/api/v1",
|
|
72
|
-
sessionExpiredCodes: void 0
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
var LIFECYCLE_KEY = /* @__PURE__ */ Symbol.for("spring:lifecycleState");
|
|
76
|
-
var BOOTSTRAPPED_KEY = /* @__PURE__ */ Symbol.for("spring:bootstrapped");
|
|
77
|
-
function createSpringInstance(overrides) {
|
|
78
|
-
const id = `spring-${++instanceCounter}`;
|
|
79
|
-
const core = createDefaultCoreState(overrides);
|
|
80
|
-
const api = createDefaultApiState();
|
|
81
|
-
const validation = validateFrameworkConfig(core.config);
|
|
82
|
-
if (!validation.valid) {
|
|
83
|
-
throw new SpringConfigError(
|
|
84
|
-
`Invalid instance configuration for "${id}":
|
|
85
|
-
- ${validation.errors.join("\n - ")}`
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
const internal = {
|
|
89
|
-
[LIFECYCLE_KEY]: "creating",
|
|
90
|
-
[BOOTSTRAPPED_KEY]: false
|
|
91
|
-
};
|
|
92
|
-
const instance = {
|
|
93
|
-
id,
|
|
94
|
-
get state() {
|
|
95
|
-
return internal[LIFECYCLE_KEY];
|
|
96
|
-
},
|
|
97
|
-
core,
|
|
98
|
-
api,
|
|
99
|
-
ui: {},
|
|
100
|
-
dispose() {
|
|
101
|
-
if (internal[LIFECYCLE_KEY] === "disposed") return;
|
|
102
|
-
internal[LIFECYCLE_KEY] = "disposing";
|
|
103
|
-
disposePlugins(instance);
|
|
104
|
-
core.eventListeners.clear();
|
|
105
|
-
core.middlewareRegistry.clear();
|
|
106
|
-
core.validatorRegistry.clear();
|
|
107
|
-
for (const controller of api.requestControllers) {
|
|
108
|
-
controller.abort();
|
|
109
|
-
}
|
|
110
|
-
api.requestControllers.clear();
|
|
111
|
-
core.authenticated = false;
|
|
112
|
-
core.logoutHandler = null;
|
|
113
|
-
core.logoutInFlight = null;
|
|
114
|
-
api.authToken = null;
|
|
115
|
-
const uiKeys = [
|
|
116
|
-
...Object.keys(instance.ui),
|
|
117
|
-
...Object.getOwnPropertySymbols(instance.ui)
|
|
118
|
-
];
|
|
119
|
-
for (const key of uiKeys) {
|
|
120
|
-
const val = instance.ui[key];
|
|
121
|
-
if (val instanceof Map) val.clear();
|
|
122
|
-
delete instance.ui[key];
|
|
123
|
-
}
|
|
124
|
-
internal[LIFECYCLE_KEY] = "disposed";
|
|
125
|
-
internal[BOOTSTRAPPED_KEY] = false;
|
|
126
|
-
clearSpringInstanceIfCurrent(instance);
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
instance[LIFECYCLE_KEY] = internal;
|
|
130
|
-
return instance;
|
|
131
|
-
}
|
|
132
|
-
function markInstanceReady(instance) {
|
|
133
|
-
if (instance.state !== "creating") return;
|
|
134
|
-
const internal = instance[LIFECYCLE_KEY];
|
|
135
|
-
if (internal) internal[LIFECYCLE_KEY] = "ready";
|
|
136
|
-
}
|
|
137
|
-
function bootstrapSpringInstance(instance, activate) {
|
|
138
|
-
if (instance.state === "disposed" || instance.state === "disposing") {
|
|
139
|
-
throw new SpringConfigError(`Cannot bootstrap disposed instance "${instance.id}".`);
|
|
140
|
-
}
|
|
141
|
-
if (instance.state === "ready") {
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
const internal = instance[LIFECYCLE_KEY];
|
|
145
|
-
const isBootstrapped = Boolean(internal?.[BOOTSTRAPPED_KEY]);
|
|
146
|
-
if (isBootstrapped) {
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
if (internal) {
|
|
150
|
-
internal[BOOTSTRAPPED_KEY] = true;
|
|
151
|
-
}
|
|
152
|
-
try {
|
|
153
|
-
activate();
|
|
154
|
-
markInstanceReady(instance);
|
|
155
|
-
} catch (error) {
|
|
156
|
-
if (internal) {
|
|
157
|
-
internal[BOOTSTRAPPED_KEY] = false;
|
|
158
|
-
}
|
|
159
|
-
clearSpringInstanceIfCurrent(instance);
|
|
160
|
-
throw error;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
function isInstanceActive(instance) {
|
|
164
|
-
return instance.state === "creating" || instance.state === "ready";
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
export {
|
|
168
|
-
createSpringInstance,
|
|
169
|
-
markInstanceReady,
|
|
170
|
-
bootstrapSpringInstance,
|
|
171
|
-
isInstanceActive
|
|
172
|
-
};
|
|
173
|
-
//# sourceMappingURL=chunk-F2SIMWZ5.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/instance/create-instance.ts"],"sourcesContent":["/**\n * Factory for creating SpringInstance — a clean state container with all defaults.\n *\n * Lifecycle: `creating` → `ready` → `disposing` → `disposed`\n *\n * @module create-instance\n */\n\nimport { createFrameworkConfig, validateFrameworkConfig } from \"../config/framework-config\";\nimport type { FrameworkConfig, FrameworkConfigOverrides } from \"../config/framework-config-types\";\nimport { SpringConfigError } from \"../errors/errors\";\nimport { DEFAULT_MESSAGES } from \"../i18n/default-messages\";\nimport { disposePlugins } from \"../plugins/plugin\";\nimport { __DEV__ } from \"../utils/dev-warnings\";\nimport { sanitizeSecurityData, type SecurityLogData } from \"../utils/security-sanitize\";\nimport { clearSpringInstanceIfCurrent } from \"./current-instance\";\nimport type { InstanceLifecycleState,SpringApiState, SpringCoreState, SpringInstance } from \"./spring-instance\";\n\n/** @global Legitimately global — monotonic counter for unique instance IDs across all instances. */\nlet instanceCounter = 0;\n\nfunction logNotification(level: \"error\" | \"info\" | \"warn\", message: string): void {\n if (!__DEV__) return;\n const prefix = \"[Notification]\";\n if (level === \"error\") {\n console.error(prefix, message);\n return;\n }\n if (level === \"warn\") {\n console.warn(prefix, message);\n return;\n }\n console.info(prefix, message);\n}\n\nfunction createDefaultCoreState(overrides?: FrameworkConfigOverrides): SpringCoreState {\n const config: FrameworkConfig = createFrameworkConfig(overrides);\n\n return {\n config,\n contentAdapter: { getRes: (key: string) => (DEFAULT_MESSAGES as Record<string, string>)[key] ?? `[${key}]` },\n notificationAdapter: {\n error: (msg: string) => logNotification(\"error\", msg),\n success: (msg: string) => logNotification(\"info\", msg),\n warning: (msg: string) => logNotification(\"warn\", msg),\n info: (msg: string) => logNotification(\"info\", msg),\n },\n logAdapter: {\n onSecurityEvent: (event: string, data?: SecurityLogData) => {\n if (!__DEV__) {\n // Keep a minimal audit trail in production without payload details.\n console.warn(`[SPRING Security] ${event}`);\n return;\n }\n console.warn(`[SPRING Security] ${event}`, sanitizeSecurityData(data));\n },\n },\n logoutHandler: null,\n authenticated: false,\n logoutInFlight: null,\n eventListeners: new Map(),\n middlewareRegistry: new Map(),\n validatorRegistry: new Map(),\n };\n}\n\nfunction createDefaultApiState(): SpringApiState {\n return {\n authToken: null,\n requestControllers: new Set(),\n requestHook: null,\n responseHook: null,\n apiPrefix: \"/api/v1\",\n sessionExpiredCodes: undefined,\n };\n}\n\n/** Symbol key for mutable lifecycle state (hidden from public API) */\nconst LIFECYCLE_KEY = Symbol.for(\"spring:lifecycleState\");\nconst BOOTSTRAPPED_KEY = Symbol.for(\"spring:bootstrapped\");\n\n/** Type-safe accessor for the internal lifecycle record stored on an instance */\ninterface InstanceWithInternal extends SpringInstance {\n [key: symbol]: Record<symbol, unknown> | undefined;\n}\n\n/**\n * Create a fresh SpringInstance with clean state.\n * Each instance gets its own event listeners, middleware registry, validators, etc.\n *\n * The instance starts in `creating` state. Call `markInstanceReady()` after\n * applying plugins and fallbacks to transition to `ready`.\n *\n * @param overrides - Partial config overrides merged with DEFAULT_FRAMEWORK_CONFIG (deep-merged per section)\n * @returns A new SpringInstance in `creating` lifecycle state with a unique ID.\n */\nexport function createSpringInstance(overrides?: FrameworkConfigOverrides): SpringInstance {\n const id = `spring-${++instanceCounter}`;\n const core = createDefaultCoreState(overrides);\n const api = createDefaultApiState();\n\n // Reject invalid config in all runtimes to keep behavior aligned with configureFramework().\n const validation = validateFrameworkConfig(core.config);\n if (!validation.valid) {\n throw new SpringConfigError(\n `Invalid instance configuration for \"${id}\":\\n - ${validation.errors.join(\"\\n - \")}`,\n );\n }\n\n const internal: Record<symbol, unknown> = {\n [LIFECYCLE_KEY]: \"creating\" as InstanceLifecycleState,\n [BOOTSTRAPPED_KEY]: false,\n };\n\n const instance: SpringInstance = {\n id,\n get state() {\n return internal[LIFECYCLE_KEY] as InstanceLifecycleState;\n },\n core,\n api,\n ui: {},\n dispose() {\n if (internal[LIFECYCLE_KEY] === \"disposed\") return;\n internal[LIFECYCLE_KEY] = \"disposing\";\n\n // Dispose plugins first — their cleanups may reference instance state\n disposePlugins(instance);\n\n // Clear event bus\n core.eventListeners.clear();\n // Clear middleware\n core.middlewareRegistry.clear();\n // Clear validators\n core.validatorRegistry.clear();\n // Abort all pending requests\n for (const controller of api.requestControllers) {\n controller.abort();\n }\n api.requestControllers.clear();\n // Clear auth state\n core.authenticated = false;\n core.logoutHandler = null;\n core.logoutInFlight = null;\n api.authToken = null;\n // Clear UI state (dialog resolvers, after-navigate map, etc.)\n // Iterate both string and symbol keys\n const uiKeys: (string | symbol)[] = [\n ...Object.keys(instance.ui),\n ...Object.getOwnPropertySymbols(instance.ui),\n ];\n for (const key of uiKeys) {\n const val = instance.ui[key];\n if (val instanceof Map) val.clear();\n delete instance.ui[key];\n }\n\n internal[LIFECYCLE_KEY] = \"disposed\";\n internal[BOOTSTRAPPED_KEY] = false;\n clearSpringInstanceIfCurrent(instance);\n },\n };\n\n // Store internal ref for markInstanceReady\n (instance as InstanceWithInternal)[LIFECYCLE_KEY] = internal;\n\n return instance;\n}\n\n/**\n * Transition an instance to `ready` state.\n * Should be called after all initialization (plugins, fallbacks, adapters) is complete.\n */\nexport function markInstanceReady(instance: SpringInstance): void {\n if (instance.state !== \"creating\") return;\n const internal = (instance as InstanceWithInternal)[LIFECYCLE_KEY];\n if (internal) internal[LIFECYCLE_KEY] = \"ready\";\n}\n\n/**\n * Run one-time activation work for an instance and transition it to `ready`.\n *\n * Safe under StrictMode and remounts:\n * - render phase may create the instance, but activation happens later\n * - repeated activation on the same ready instance is a no-op\n * - bootstrap failures clear the current-instance bridge before rethrowing\n */\nexport function bootstrapSpringInstance(instance: SpringInstance, activate: () => void): void {\n if (instance.state === \"disposed\" || instance.state === \"disposing\") {\n throw new SpringConfigError(`Cannot bootstrap disposed instance \"${instance.id}\".`);\n }\n\n if (instance.state === \"ready\") {\n return;\n }\n\n const internal = (instance as InstanceWithInternal)[LIFECYCLE_KEY];\n const isBootstrapped = Boolean(internal?.[BOOTSTRAPPED_KEY]);\n if (isBootstrapped) {\n return;\n }\n\n if (internal) {\n internal[BOOTSTRAPPED_KEY] = true;\n }\n\n try {\n activate();\n markInstanceReady(instance);\n } catch (error) {\n if (internal) {\n internal[BOOTSTRAPPED_KEY] = false;\n }\n clearSpringInstanceIfCurrent(instance);\n throw error;\n }\n}\n\n/**\n * Check if an instance is in a usable state (creating or ready).\n */\nexport function isInstanceActive(instance: SpringInstance): boolean {\n return instance.state === \"creating\" || instance.state === \"ready\";\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAmBA,IAAI,kBAAkB;AAEtB,SAAS,gBAAgB,OAAkC,SAAuB;AAC9E,MAAI,CAAC,QAAS;AACd,QAAM,SAAS;AACf,MAAI,UAAU,SAAS;AACnB,YAAQ,MAAM,QAAQ,OAAO;AAC7B;AAAA,EACJ;AACA,MAAI,UAAU,QAAQ;AAClB,YAAQ,KAAK,QAAQ,OAAO;AAC5B;AAAA,EACJ;AACA,UAAQ,KAAK,QAAQ,OAAO;AAChC;AAEA,SAAS,uBAAuB,WAAuD;AACnF,QAAM,SAA0B,sBAAsB,SAAS;AAE/D,SAAO;AAAA,IACH;AAAA,IACA,gBAAgB,EAAE,QAAQ,CAAC,QAAiB,iBAA4C,GAAG,KAAK,IAAI,G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