@codeleap/debug 6.8.0 → 7.0.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.
@@ -0,0 +1,133 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import { globalState } from '@codeleap/store';
13
+ import { TypeGuards } from '@codeleap/types';
14
+ import { capitalize, deepEqual } from '@codeleap/utils';
15
+ import { useState, useMemo } from 'react';
16
+ import { EDITORS } from './const';
17
+ /**
18
+ * Runtime switchboard for backend environments in debug builds.
19
+ *
20
+ * The override is opt-in: until `setEnabled` is called the manager always
21
+ * returns `defaultEnvironment`, making it safe to instantiate unconditionally.
22
+ * State is persisted via `@codeleap/store` `globalState` so it survives page
23
+ * reloads, but the `enabledBy` flag gates whether that persisted state is
24
+ * actually honoured.
25
+ *
26
+ * When the active environment is `customEnvironment`, `serverUrl` validates the
27
+ * stored URL against a strict regex and falls back to `defaultEnvironment` if
28
+ * it fails — callers can rely on `serverUrl` always returning a usable value.
29
+ */
30
+ export class EnvironmentManager {
31
+ get environments() {
32
+ return this.config.environments;
33
+ }
34
+ get defaultConfig() {
35
+ return {
36
+ environment: this.config.defaultEnvironment,
37
+ customUrl: '',
38
+ enabledBy: null,
39
+ };
40
+ }
41
+ constructor(config) {
42
+ var _a;
43
+ this.config = config;
44
+ this.editors = EDITORS;
45
+ this.store = globalState(this.defaultConfig, { persistKey: (_a = config === null || config === void 0 ? void 0 : config.persistKey) !== null && _a !== void 0 ? _a : 'environment-manager' });
46
+ this.initialStoreValue = this.store.get();
47
+ }
48
+ testUrl(url) {
49
+ if (!url)
50
+ return false;
51
+ const urlValidator = /^https?:\/\/([a-zA-Z0-9.-]+|localhost|(\d{1,3}\.){3}\d{1,3})(?::\d+)?\/$/;
52
+ return urlValidator.test(url);
53
+ }
54
+ get env() {
55
+ var _a;
56
+ const value = (_a = this.store.get()) !== null && _a !== void 0 ? _a : this.defaultConfig;
57
+ if (value.enabledBy) {
58
+ if (value.environment === this.config.customEnvironment && !this.testUrl(value.customUrl)) {
59
+ value.environment = this.defaultConfig.environment;
60
+ }
61
+ return value;
62
+ }
63
+ return this.defaultConfig;
64
+ }
65
+ setEnabled(by = false) {
66
+ const disable = by === false || TypeGuards.isNil(by);
67
+ this.store.set({ enabledBy: disable ? null : by });
68
+ return !disable;
69
+ }
70
+ get isEnabled() {
71
+ return !TypeGuards.isNil(this.isEnabledBy);
72
+ }
73
+ get isEnabledBy() {
74
+ return this.store.get(s => s === null || s === void 0 ? void 0 : s.enabledBy);
75
+ }
76
+ get isEnabledBySystem() {
77
+ return this.isEnabledBy === EDITORS.SYSTEM;
78
+ }
79
+ get isEnabledByUser() {
80
+ return this.isEnabledBy === EDITORS.USER;
81
+ }
82
+ get is() {
83
+ const environment = this.store.get(s => { var _a; return (_a = s === null || s === void 0 ? void 0 : s.environment) !== null && _a !== void 0 ? _a : this.defaultConfig.environment; });
84
+ return Object.entries(this.environments).reduce((acc, [key, value]) => {
85
+ acc[capitalize(key)] = environment === key;
86
+ return acc;
87
+ }, {});
88
+ }
89
+ get serverUrl() {
90
+ var _a;
91
+ const env = this.env;
92
+ if (env.environment === this.config.customEnvironment) {
93
+ if (!this.testUrl(env.customUrl)) {
94
+ return this.environments[this.defaultConfig.environment];
95
+ }
96
+ return env.customUrl;
97
+ }
98
+ return (_a = this.environments[env.environment]) !== null && _a !== void 0 ? _a : this.environments[this.defaultConfig.environment];
99
+ }
100
+ setEnvironment(environment) {
101
+ if (!this.isEnabled)
102
+ return;
103
+ this.store.set({ environment });
104
+ }
105
+ isEnvironment(env) {
106
+ const current = this.env;
107
+ return current.environment === env;
108
+ }
109
+ setCustomUrl(url) {
110
+ if (!url.endsWith('/')) {
111
+ url += '/';
112
+ }
113
+ if (!this.testUrl(url))
114
+ return;
115
+ this.store.set({ customUrl: url });
116
+ }
117
+ use() {
118
+ const value = this.store.use();
119
+ const _a = value !== null && value !== void 0 ? value : this.defaultConfig, { enabledBy } = _a, config = __rest(_a, ["enabledBy"]);
120
+ const [customUrl, setCustomUrl] = useState(config === null || config === void 0 ? void 0 : config.customUrl);
121
+ const changed = useMemo(() => !deepEqual(value, this.initialStoreValue), [value]);
122
+ return {
123
+ enabled: !!enabledBy,
124
+ enabledByUser: enabledBy === EDITORS.USER,
125
+ enabledBySystem: enabledBy === EDITORS.SYSTEM,
126
+ config,
127
+ changed,
128
+ customUrl,
129
+ setCustomUrl,
130
+ };
131
+ }
132
+ }
133
+ //# sourceMappingURL=class.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"class.js","sourceRoot":"","sources":["../../src/EnvironmentManager/class.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAC7C,OAAO,EAAuB,UAAU,EAAE,MAAM,iBAAiB,CAAA;AACjE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AACvD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAEzC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAEjC;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,kBAAkB;IAO7B,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,MAAM,CAAC,YAAY,CAAA;IACjC,CAAC;IAED,IAAI,aAAa;QACf,OAAO;YACL,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,kBAAkB;YAC3C,SAAS,EAAE,EAAE;YACb,SAAS,EAAE,IAAI;SACO,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GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,iBAAiB,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAA;QAEjF,OAAO;YACL,OAAO,EAAE,CAAC,CAAC,SAAS;YACpB,aAAa,EAAE,SAAS,KAAK,OAAO,CAAC,IAAI;YACzC,eAAe,EAAE,SAAS,KAAK,OAAO,CAAC,MAAM;YAC7C,MAAM;YACN,OAAO;YACP,SAAS;YACT,YAAY;SACb,CAAA;IACH,CAAC;CACF"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Identifies who enabled the environment override — the application itself
3
+ * (`SYSTEM`) or an end user via a debug UI (`USER`). Used to gate which
4
+ * controls are exposed and whether the override survives a session reset.
5
+ */
6
+ export const EDITORS = {
7
+ SYSTEM: 'system',
8
+ USER: 'user',
9
+ };
10
+ //# sourceMappingURL=const.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"const.js","sourceRoot":"","sources":["../../src/EnvironmentManager/const.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,MAAM,EAAE,QAAQ;IAChB,IAAI,EAAE,MAAM;CACJ,CAAA"}
@@ -0,0 +1,10 @@
1
+ import { EnvironmentManager } from './class';
2
+ /**
3
+ * Preferred entry point for instantiating an `EnvironmentManager`.
4
+ * Keeps call-sites free of the generic `new` syntax and makes the config
5
+ * shape the only public API surface that needs to be imported.
6
+ */
7
+ export function createEnvironmentManager(config) {
8
+ return new EnvironmentManager(config);
9
+ }
10
+ //# sourceMappingURL=factor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"factor.js","sourceRoot":"","sources":["../../src/EnvironmentManager/factor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAG5C;;;;GAIG;AACH,MAAM,UAAU,wBAAwB,CAAyB,MAAmC;IAClG,OAAO,IAAI,kBAAkB,CAAI,MAAM,CAAC,CAAA;AAC1C,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from './factor';
2
+ export * from './class';
3
+ export * from './types';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/EnvironmentManager/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,SAAS,CAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/EnvironmentManager/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,213 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ /**
11
+ * A fake REST API implementation for testing and prototyping.
12
+ * Provides CRUD operations with pagination support and optional request delays.
13
+ * @template T - The type of items to manage, must extend FakeItem
14
+ * @template F - The type of filters to apply when listing items
15
+ */
16
+ export class FakeRestApi {
17
+ /**
18
+ * Gets the ID of the last item in the data array.
19
+ * @private
20
+ * @returns The highest ID or 0 if no items exist
21
+ */
22
+ get lastId() {
23
+ return this.data.length > 0 ? Math.max(...this.data.map((i) => i.id)) : 0;
24
+ }
25
+ /**
26
+ * Gets the name of the API.
27
+ * @returns The API name
28
+ */
29
+ get name() {
30
+ return this.options.name;
31
+ }
32
+ /**
33
+ * Gets the current count of items.
34
+ * @returns The number of items in the data array
35
+ */
36
+ get count() {
37
+ return this.data.length;
38
+ }
39
+ /**
40
+ * Creates a new FakeRestApi instance.
41
+ * @param options - Configuration options for the API
42
+ */
43
+ constructor(options) {
44
+ this.data = [];
45
+ this.options = Object.assign({ delayMs: 2500, maxCount: 100, enableDelay: false, filterFn: () => true }, options);
46
+ this.initialize();
47
+ }
48
+ /**
49
+ * Initializes the data array with items up to maxCount.
50
+ * @private
51
+ */
52
+ initialize() {
53
+ this.data = Array.from({ length: this.options.maxCount }, (_, i) => this.generateItem(i + 1));
54
+ }
55
+ /**
56
+ * Updates the API options partially.
57
+ * @param newOptions - Partial options to update
58
+ */
59
+ setOptions(newOptions) {
60
+ this.options = Object.assign(Object.assign({}, this.options), newOptions);
61
+ }
62
+ /**
63
+ * Generates a new item using the generator function.
64
+ * @param id - The ID for the new item (defaults to lastId + 1)
65
+ * @returns A newly generated item
66
+ */
67
+ generateItem(id = this.lastId + 1) {
68
+ return this.options.generatorFn(id);
69
+ }
70
+ /**
71
+ * Introduces an artificial delay if enabled in options.
72
+ * @private
73
+ * @returns A promise that resolves after the delay period
74
+ */
75
+ delay() {
76
+ return __awaiter(this, void 0, void 0, function* () {
77
+ if (!this.options.enableDelay)
78
+ return;
79
+ return new Promise((resolve) => {
80
+ setTimeout(resolve, this.options.delayMs);
81
+ });
82
+ });
83
+ }
84
+ /**
85
+ * Builds a URL with pagination parameters.
86
+ * @private
87
+ * @param limit - Number of items per page
88
+ * @param offset - Starting position
89
+ * @returns A formatted URL string
90
+ */
91
+ buildUrl(limit, offset) {
92
+ return `https://api.${this.name}?limit=${limit}&offset=${offset}`;
93
+ }
94
+ /**
95
+ * Retrieves a paginated list of items with optional filtering.
96
+ * @param limit - Number of items to return (default: 10)
97
+ * @param offset - Starting position (default: 0)
98
+ * @param filters - Optional filters to apply
99
+ * @returns A promise that resolves to a paginated response
100
+ */
101
+ listItems() {
102
+ return __awaiter(this, arguments, void 0, function* (limit = 10, offset = 0, filters) {
103
+ yield this.delay();
104
+ const hasFilters = filters && Object.keys(filters).length > 0;
105
+ const items = hasFilters
106
+ ? this.data.filter((item) => this.options.filterFn(item, filters))
107
+ : this.data;
108
+ const total = items.length;
109
+ const start = Math.max(0, offset);
110
+ const end = Math.min(start + limit, total);
111
+ const results = items.slice(start, end);
112
+ return {
113
+ count: total,
114
+ next: end < total ? this.buildUrl(limit, end) : null,
115
+ previous: start > 0 ? this.buildUrl(limit, Math.max(0, start - limit)) : null,
116
+ results,
117
+ };
118
+ });
119
+ }
120
+ /**
121
+ * Retrieves a single item by ID.
122
+ * @param id - The ID of the item to retrieve
123
+ * @returns A promise that resolves to the requested item
124
+ * @throws {Error} If the item is not found
125
+ */
126
+ retrieveItem(id) {
127
+ return __awaiter(this, void 0, void 0, function* () {
128
+ yield this.delay();
129
+ const item = this.data.find((i) => i.id === id);
130
+ if (!item) {
131
+ throw new Error(`${this.name} with id ${id} not found`);
132
+ }
133
+ return item;
134
+ });
135
+ }
136
+ /**
137
+ * Creates a new item and adds it to the data array.
138
+ * @param item - Optional partial item data (ID will be auto-generated)
139
+ * @returns A promise that resolves to the created item
140
+ */
141
+ createItem(item) {
142
+ return __awaiter(this, void 0, void 0, function* () {
143
+ yield this.delay();
144
+ const id = this.lastId + 1;
145
+ const newItem = item ? Object.assign(Object.assign({}, item), { id }) : this.generateItem(id);
146
+ this.data.push(newItem);
147
+ return newItem;
148
+ });
149
+ }
150
+ /**
151
+ * Updates an existing item by ID.
152
+ * @param id - The ID of the item to update
153
+ * @param updates - Partial item data to update
154
+ * @returns A promise that resolves to the updated item
155
+ * @throws {Error} If the item is not found
156
+ */
157
+ updateItem(id, updates) {
158
+ return __awaiter(this, void 0, void 0, function* () {
159
+ yield this.delay();
160
+ const index = this.data.findIndex((i) => i.id === id);
161
+ if (index === -1) {
162
+ throw new Error(`${this.name} with id ${id} not found`);
163
+ }
164
+ this.data[index] = Object.assign(Object.assign(Object.assign({}, this.data[index]), updates), { id });
165
+ return this.data[index];
166
+ });
167
+ }
168
+ /**
169
+ * Deletes an item by ID.
170
+ * @param id - The ID of the item to delete
171
+ * @returns A promise that resolves to the deleted item
172
+ * @throws {Error} If the item is not found
173
+ */
174
+ deleteItem(id) {
175
+ return __awaiter(this, void 0, void 0, function* () {
176
+ yield this.delay();
177
+ const index = this.data.findIndex((i) => i.id === id);
178
+ if (index === -1) {
179
+ throw new Error(`${this.name} with id ${id} not found`);
180
+ }
181
+ const [deleted] = this.data.splice(index, 1);
182
+ return deleted;
183
+ });
184
+ }
185
+ /**
186
+ * Resets the data array to its initial state by regenerating all items.
187
+ */
188
+ reset() {
189
+ this.initialize();
190
+ }
191
+ /**
192
+ * Clears all items from the data array.
193
+ */
194
+ clear() {
195
+ this.data = [];
196
+ }
197
+ /**
198
+ * Gets a readonly copy of all items in the data array.
199
+ * @returns A frozen array of all items
200
+ */
201
+ getData() {
202
+ return Object.freeze([...this.data]);
203
+ }
204
+ /**
205
+ * Gets a single item by ID without delay.
206
+ * @param id - The ID of the item to retrieve
207
+ * @returns The item if found, undefined otherwise
208
+ */
209
+ getItem(id) {
210
+ return this.data.find((i) => i.id === id);
211
+ }
212
+ }
213
+ //# sourceMappingURL=class.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"class.js","sourceRoot":"","sources":["../../src/FakeRestApi/class.ts"],"names":[],"mappings":";;;;;;;;;AAEA;;;;;GAKG;AACH,MAAM,OAAO,WAAW;IAItB;;;;OAIG;IACH,IAAY,MAAM;QAChB,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAC3E,CAAC;IAED;;;OAGG;IACH,IAAW,IAAI;QACb,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAA;IAC1B,CAAC;IAED;;;OA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;YAE1D,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QACzB,CAAC;KAAA;IAED;;;;;OAKG;IACG,UAAU,CAAC,EAAW;;YAC1B,MAAM,IAAI,CAAC,KAAK,EAAE,CAAA;YAElB,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAA;YAErD,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC;gBACjB,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,CAAC,IAAI,YAAY,EAAE,YAAY,CAAC,CAAA;YACzD,CAAC;YAED,MAAM,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;YAE5C,OAAO,OAAO,CAAA;QAChB,CAAC;KAAA;IAED;;OAEG;IACI,KAAK;QACV,IAAI,CAAC,UAAU,EAAE,CAAA;IACnB,CAAC;IAED;;OAEG;IACI,KAAK;QACV,IAAI,CAAC,IAAI,GAAG,EAAE,CAAA;IAChB,CAAC;IAED;;;OAGG;IACI,OAAO;QACZ,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;IACtC,CAAC;IAED;;;;OAIG;IACI,OAAO,CAAC,EAAW;QACxB,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAA;IAC3C,CAAC;CACF"}
@@ -0,0 +1,26 @@
1
+ import { FakeRestApi } from './class';
2
+ /**
3
+ * Factory function to create a new FakeRestApi instance.
4
+ * @template T - The type of items to manage, must extend FakeItem
5
+ * @template F - The type of filters to apply when listing items
6
+ * @param options - Configuration options for the API
7
+ * @returns A new FakeRestApi instance
8
+ * @example
9
+ * ```typescript
10
+ * type User = { id: number; name: string; email: string }
11
+ *
12
+ * const api = createFakeRestApi<User>({
13
+ * name: 'users',
14
+ * maxCount: 50,
15
+ * generatorFn: (id) => ({
16
+ * id,
17
+ * name: `User ${id}`,
18
+ * email: `user${id}@example.com`
19
+ * })
20
+ * })
21
+ * ```
22
+ */
23
+ export function createFakeRestApi(options) {
24
+ return new FakeRestApi(options);
25
+ }
26
+ //# sourceMappingURL=factor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"factor.js","sourceRoot":"","sources":["../../src/FakeRestApi/factor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAGrC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,iBAAiB,CAC/B,OAAiC;IAEjC,OAAO,IAAI,WAAW,CAAO,OAAO,CAAC,CAAA;AACvC,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './factor';
2
+ export * from './class';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/FakeRestApi/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/FakeRestApi/types.ts"],"names":[],"mappings":""}
package/dist/faker.js ADDED
@@ -0,0 +1,37 @@
1
+ const names = [
2
+ 'James', 'John', 'Robert', 'Michael', 'William', 'David', 'Richard', 'Joseph', 'Thomas',
3
+ 'Charles', 'Christopher', 'Daniel', 'Matthew', 'Anthony', 'Donald', 'Mark', 'Paul', 'Steven',
4
+ 'Andrew', 'Kenneth', 'Joshua', 'Kevin', 'Brian', 'George', 'Edward', 'Ronald', 'Timothy',
5
+ 'Jason', 'Jeffrey', 'Ryan', 'Gary', 'Jacob'
6
+ ];
7
+ const surnames = [
8
+ 'Smith', 'Johnson', 'Williams', 'Brown', 'Jones', 'Garcia', 'Miller', 'Davis',
9
+ 'Lopez', 'Wilson', 'Anderson', 'Thomas', 'Taylor', 'Moore',
10
+ 'Jackson', 'Martin', 'Lee', 'Perez', 'Thompson', 'White', 'Harris', 'Sanchez', 'Clark',
11
+ 'Ramirez', 'Lewis', 'Robinson', 'Walker', 'Young', 'Allen', 'King', 'Wright', 'Scott', 'Torres',
12
+ ];
13
+ const animals = [
14
+ 'lion', 'tiger', 'zebra', 'panda', 'koala', 'bear',
15
+ 'wolf', 'fox', 'rabbit', 'bat', 'spider', 'frog', 'shark'
16
+ ];
17
+ function getRandom(list) {
18
+ return list[Math.floor(Math.random() * list.length)];
19
+ }
20
+ function number(min = 0, max = 100) {
21
+ return Math.floor(Math.random() * (max - min + 1)) + min;
22
+ }
23
+ /**
24
+ * Lightweight fixture-data helper for tests and Storybook stories.
25
+ * All string generators draw from fixed lists, so output is deterministic
26
+ * in terms of domain (real-looking names/animals) but random in selection —
27
+ * not suitable as a seed-based reproducible faker. Use `number(min, max)`
28
+ * for bounded integers.
29
+ */
30
+ export const faker = {
31
+ lastName: () => getRandom(surnames),
32
+ firstName: () => getRandom(names),
33
+ animal: () => getRandom(animals),
34
+ number,
35
+ name: () => `${getRandom(names)} ${getRandom(surnames)}`
36
+ };
37
+ //# sourceMappingURL=faker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"faker.js","sourceRoot":"","sources":["../src/faker.ts"],"names":[],"mappings":"AAAA,MAAM,KAAK,GAAG;IACZ,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ;IACvF,SAAS,EAAE,aAAa,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ;IAC5F,QAAQ,EAAE,SAAS,EAAE,QAAQ,EA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AAS,CAAC,QAAQ,CAAC;IACnC,SAAS,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC;IACjC,MAAM,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC;IAChC,MAAM;IACN,IAAI,EAAE,GAAG,EAAE,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,IAAI,SAAS,CAAC,QAAQ,CAAC,EAAE;CACzD,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export * from './FakeRestApi';
2
+ export * from './EnvironmentManager';
3
+ export * from './faker';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,cAAc,sBAAsB,CAAA;AACpC,cAAc,SAAS,CAAA"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@codeleap/debug",
3
- "version": "6.8.0",
4
- "main": "src/index.ts",
3
+ "version": "7.0.1",
4
+ "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "exports": {
7
7
  ".": {
@@ -22,10 +22,10 @@
22
22
  "directory": "packages/debug"
23
23
  },
24
24
  "devDependencies": {
25
- "@codeleap/config": "6.8.0",
26
- "@codeleap/store": "6.8.0",
27
- "@codeleap/types": "6.8.0",
28
- "@codeleap/utils": "6.8.0",
25
+ "@codeleap/config": "7.0.1",
26
+ "@codeleap/store": "7.0.1",
27
+ "@codeleap/types": "7.0.1",
28
+ "@codeleap/utils": "7.0.1",
29
29
  "ts-node-dev": "1.1.8"
30
30
  },
31
31
  "scripts": {
@@ -34,9 +34,9 @@
34
34
  },
35
35
  "peerDependencies": {
36
36
  "typescript": "5.5.2",
37
- "@codeleap/config": "6.8.0",
38
- "@codeleap/store": "6.8.0",
39
- "@codeleap/types": "6.8.0",
40
- "@codeleap/utils": "6.8.0"
37
+ "@codeleap/config": "7.0.1",
38
+ "@codeleap/store": "7.0.1",
39
+ "@codeleap/types": "7.0.1",
40
+ "@codeleap/utils": "7.0.1"
41
41
  }
42
42
  }