@adonisjs/lock 2.0.0 → 2.1.0-next.0
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/build/index.js +96 -154
- package/build/providers/lock_provider.js +20 -31
- package/build/services/main.d.ts +2 -2
- package/build/services/main.js +3 -8
- package/build/src/types.js +1 -1
- package/build/tests/helpers.d.ts +1 -1
- package/package.json +21 -18
- package/build/chunk-MLKGABMK.js +0 -9
package/build/index.js
CHANGED
|
@@ -1,161 +1,103 @@
|
|
|
1
|
-
import
|
|
2
|
-
__export
|
|
3
|
-
} from "./chunk-MLKGABMK.js";
|
|
4
|
-
|
|
5
|
-
// src/stores.ts
|
|
1
|
+
import "node:module";
|
|
6
2
|
import { configProvider } from "@adonisjs/core";
|
|
7
|
-
import { RuntimeException } from "@adonisjs/core/exceptions";
|
|
8
|
-
var stores = {
|
|
9
|
-
/**
|
|
10
|
-
* Redis store
|
|
11
|
-
* You must install @adonisjs/redis to use this driver
|
|
12
|
-
*/
|
|
13
|
-
redis(config) {
|
|
14
|
-
return configProvider.create(async (app) => {
|
|
15
|
-
const redis = await app.container.make("redis");
|
|
16
|
-
const { redisStore } = await import("@verrou/core/drivers/redis");
|
|
17
|
-
const redisConnection = redis.connection(config.connectionName);
|
|
18
|
-
const store = redisStore({ connection: redisConnection.ioConnection });
|
|
19
|
-
return { driver: store };
|
|
20
|
-
});
|
|
21
|
-
},
|
|
22
|
-
/**
|
|
23
|
-
* Memory store
|
|
24
|
-
*/
|
|
25
|
-
memory() {
|
|
26
|
-
return configProvider.create(async () => {
|
|
27
|
-
const { memoryStore } = await import("@verrou/core/drivers/memory");
|
|
28
|
-
return { driver: memoryStore() };
|
|
29
|
-
});
|
|
30
|
-
},
|
|
31
|
-
/**
|
|
32
|
-
* Database store
|
|
33
|
-
* You must install @adonisjs/lucid to use this driver
|
|
34
|
-
*/
|
|
35
|
-
database(config) {
|
|
36
|
-
return configProvider.create(async (app) => {
|
|
37
|
-
const db = await app.container.make("lucid.db");
|
|
38
|
-
const connectionName = config?.connectionName || db.primaryConnectionName;
|
|
39
|
-
const connection = db.manager.get(connectionName);
|
|
40
|
-
if (!connection) {
|
|
41
|
-
throw new RuntimeException(
|
|
42
|
-
`Invalid connection name "${connectionName}" referenced by "config/lock.ts" file. First register the connection inside "config/database.ts" file`
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
const dialect = db.connection(connectionName).dialect.name;
|
|
46
|
-
const supportedDialects = ["postgres", "mysql", "better-sqlite3", "sqlite3"];
|
|
47
|
-
if (!supportedDialects.includes(dialect)) {
|
|
48
|
-
throw new Error(`Unsupported dialect "${dialect}"`);
|
|
49
|
-
}
|
|
50
|
-
const rawConnection = db.getRawConnection(connectionName);
|
|
51
|
-
if (!rawConnection?.connection?.client) {
|
|
52
|
-
throw new Error(`Unable to get raw connection for "${connectionName}"`);
|
|
53
|
-
}
|
|
54
|
-
const { knexStore } = await import("@verrou/core/drivers/knex");
|
|
55
|
-
const store = knexStore({
|
|
56
|
-
connection: rawConnection.connection.client,
|
|
57
|
-
tableName: config?.tableName,
|
|
58
|
-
autoCreateTable: false
|
|
59
|
-
});
|
|
60
|
-
return { driver: store };
|
|
61
|
-
});
|
|
62
|
-
},
|
|
63
|
-
/**
|
|
64
|
-
* DynamoDB store
|
|
65
|
-
* You must install @aws-sdk/client-dynamodb to use this driver
|
|
66
|
-
*/
|
|
67
|
-
dynamodb(config) {
|
|
68
|
-
return configProvider.create(async () => {
|
|
69
|
-
const { dynamodbStore } = await import("@verrou/core/drivers/dynamodb");
|
|
70
|
-
return { driver: dynamodbStore(config) };
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
// src/errors.ts
|
|
76
|
-
var errors_exports = {};
|
|
77
|
-
__export(errors_exports, {
|
|
78
|
-
E_LOCK_NOT_OWNED: () => E_LOCK_NOT_OWNED,
|
|
79
|
-
E_LOCK_STORAGE_ERROR: () => E_LOCK_STORAGE_ERROR
|
|
80
|
-
});
|
|
3
|
+
import { InvalidArgumentsException, RuntimeException } from "@adonisjs/core/exceptions";
|
|
81
4
|
import { E_LOCK_NOT_OWNED, E_LOCK_STORAGE_ERROR } from "@verrou/core";
|
|
82
|
-
|
|
83
|
-
// configure.ts
|
|
84
5
|
import string from "@adonisjs/core/helpers/string";
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __exportAll = (all, symbols) => {
|
|
8
|
+
let target = {};
|
|
9
|
+
for (var name in all) __defProp(target, name, {
|
|
10
|
+
get: all[name],
|
|
11
|
+
enumerable: true
|
|
12
|
+
});
|
|
13
|
+
if (symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
14
|
+
return target;
|
|
15
|
+
};
|
|
16
|
+
const stores = {
|
|
17
|
+
redis(config) {
|
|
18
|
+
return configProvider.create(async (app) => {
|
|
19
|
+
const redis = await app.container.make("redis");
|
|
20
|
+
const { redisStore } = await import("@verrou/core/drivers/redis");
|
|
21
|
+
return { driver: redisStore({ connection: redis.connection(config.connectionName).ioConnection }) };
|
|
22
|
+
});
|
|
23
|
+
},
|
|
24
|
+
memory() {
|
|
25
|
+
return configProvider.create(async () => {
|
|
26
|
+
const { memoryStore } = await import("@verrou/core/drivers/memory");
|
|
27
|
+
return { driver: memoryStore() };
|
|
28
|
+
});
|
|
29
|
+
},
|
|
30
|
+
database(config) {
|
|
31
|
+
return configProvider.create(async (app) => {
|
|
32
|
+
const db = await app.container.make("lucid.db");
|
|
33
|
+
const connectionName = config?.connectionName || db.primaryConnectionName;
|
|
34
|
+
if (!db.manager.get(connectionName)) throw new RuntimeException(`Invalid connection name "${connectionName}" referenced by "config/lock.ts" file. First register the connection inside "config/database.ts" file`);
|
|
35
|
+
const dialect = db.connection(connectionName).dialect.name;
|
|
36
|
+
if (![
|
|
37
|
+
"postgres",
|
|
38
|
+
"mysql",
|
|
39
|
+
"better-sqlite3",
|
|
40
|
+
"sqlite3"
|
|
41
|
+
].includes(dialect)) throw new Error(`Unsupported dialect "${dialect}"`);
|
|
42
|
+
const rawConnection = db.getRawConnection(connectionName);
|
|
43
|
+
if (!rawConnection?.connection?.client) throw new Error(`Unable to get raw connection for "${connectionName}"`);
|
|
44
|
+
const { knexStore } = await import("@verrou/core/drivers/knex");
|
|
45
|
+
return { driver: knexStore({
|
|
46
|
+
connection: rawConnection.connection.client,
|
|
47
|
+
tableName: config?.tableName,
|
|
48
|
+
autoCreateTable: false
|
|
49
|
+
}) };
|
|
50
|
+
});
|
|
51
|
+
},
|
|
52
|
+
dynamodb(config) {
|
|
53
|
+
return configProvider.create(async () => {
|
|
54
|
+
const { dynamodbStore } = await import("@verrou/core/drivers/dynamodb");
|
|
55
|
+
return { driver: dynamodbStore(config) };
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
var errors_exports = /* @__PURE__ */ __exportAll({
|
|
60
|
+
E_LOCK_NOT_OWNED: () => E_LOCK_NOT_OWNED,
|
|
61
|
+
E_LOCK_STORAGE_ERROR: () => E_LOCK_STORAGE_ERROR
|
|
62
|
+
});
|
|
63
|
+
const stubsRoot = import.meta.dirname;
|
|
64
|
+
const KNOWN_STORES = [
|
|
65
|
+
"database",
|
|
66
|
+
"redis",
|
|
67
|
+
"dynamodb"
|
|
68
|
+
];
|
|
91
69
|
async function configure(command) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
rcFile.addProvider("@adonisjs/lock/lock_provider");
|
|
119
|
-
});
|
|
120
|
-
if (selectedStore === "database") {
|
|
121
|
-
await codemods.makeUsingStub(stubsRoot, "make/migration/locks.stub", {
|
|
122
|
-
entity: command.app.generators.createEntity("locks"),
|
|
123
|
-
migration: {
|
|
124
|
-
folder: "database/migrations",
|
|
125
|
-
fileName: `${(/* @__PURE__ */ new Date()).getTime()}_create_locks_table.ts`
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
await codemods.defineEnvVariables({
|
|
130
|
-
LOCK_STORE: selectedStore
|
|
131
|
-
});
|
|
132
|
-
await codemods.defineEnvValidations({
|
|
133
|
-
leadingComment: "Variables for configuring the lock package",
|
|
134
|
-
variables: {
|
|
135
|
-
LOCK_STORE: `Env.schema.enum(['${selectedStore}', 'memory'] as const)`
|
|
136
|
-
}
|
|
137
|
-
});
|
|
70
|
+
let selectedStore = command.parsedFlags.store;
|
|
71
|
+
if (!selectedStore) selectedStore = await command.prompt.choice("Select the storage layer you want to use", KNOWN_STORES, { validate(value) {
|
|
72
|
+
return !value ? "Please select a store" : true;
|
|
73
|
+
} });
|
|
74
|
+
if (!KNOWN_STORES.includes(selectedStore)) {
|
|
75
|
+
command.exitCode = 1;
|
|
76
|
+
command.logger.logError(`Invalid lock store "${selectedStore}". Supported stores are: ${string.sentence(KNOWN_STORES)}`);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const codemods = await command.createCodemods();
|
|
80
|
+
await codemods.makeUsingStub(stubsRoot, "config/lock.stub", { store: selectedStore });
|
|
81
|
+
await codemods.updateRcFile((rcFile) => {
|
|
82
|
+
rcFile.addProvider("@adonisjs/lock/lock_provider");
|
|
83
|
+
});
|
|
84
|
+
if (selectedStore === "database") await codemods.makeUsingStub(stubsRoot, "make/migration/locks.stub", {
|
|
85
|
+
entity: command.app.generators.createEntity("locks"),
|
|
86
|
+
migration: {
|
|
87
|
+
folder: "database/migrations",
|
|
88
|
+
fileName: `${(/* @__PURE__ */ new Date()).getTime()}_create_locks_table.ts`
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
await codemods.defineEnvVariables({ LOCK_STORE: selectedStore });
|
|
92
|
+
await codemods.defineEnvValidations({
|
|
93
|
+
leadingComment: "Variables for configuring the lock package",
|
|
94
|
+
variables: { LOCK_STORE: `Env.schema.enum(['${selectedStore}', 'memory'] as const)` }
|
|
95
|
+
});
|
|
138
96
|
}
|
|
139
|
-
|
|
140
|
-
// src/define_config.ts
|
|
141
|
-
import { InvalidArgumentsException } from "@adonisjs/core/exceptions";
|
|
142
97
|
function defineConfig(config) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
throw new InvalidArgumentsException('Missing "default" store in lock config');
|
|
148
|
-
}
|
|
149
|
-
if (!config.stores[config.default]) {
|
|
150
|
-
throw new InvalidArgumentsException(
|
|
151
|
-
`Missing "stores.${config.default.toString()}" in lock config. It is referenced by the "default" property`
|
|
152
|
-
);
|
|
153
|
-
}
|
|
154
|
-
return config;
|
|
98
|
+
if (!config.stores) throw new InvalidArgumentsException("Missing \"stores\" property in lock config");
|
|
99
|
+
if (!config.default) throw new InvalidArgumentsException("Missing \"default\" store in lock config");
|
|
100
|
+
if (!config.stores[config.default]) throw new InvalidArgumentsException(`Missing "stores.${config.default.toString()}" in lock config. It is referenced by the "default" property`);
|
|
101
|
+
return config;
|
|
155
102
|
}
|
|
156
|
-
export {
|
|
157
|
-
configure,
|
|
158
|
-
defineConfig,
|
|
159
|
-
errors_exports as errors,
|
|
160
|
-
stores
|
|
161
|
-
};
|
|
103
|
+
export { configure, defineConfig, errors_exports as errors, stores };
|
|
@@ -1,33 +1,22 @@
|
|
|
1
|
-
import "../chunk-MLKGABMK.js";
|
|
2
|
-
|
|
3
|
-
// providers/lock_provider.ts
|
|
4
1
|
var LockProvider = class {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return new Verrou({
|
|
25
|
-
default: config.default,
|
|
26
|
-
stores: Object.fromEntries(await Promise.all(stores))
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
export {
|
|
32
|
-
LockProvider as default
|
|
2
|
+
constructor(app) {
|
|
3
|
+
this.app = app;
|
|
4
|
+
}
|
|
5
|
+
register() {
|
|
6
|
+
this.app.container.singleton("lock.manager", async () => {
|
|
7
|
+
const { Verrou } = await import("@verrou/core");
|
|
8
|
+
const config = this.app.config.get("lock", {});
|
|
9
|
+
const stores = Object.entries(config.stores).map(async ([name, store]) => {
|
|
10
|
+
let resolvedStore;
|
|
11
|
+
if ("resolver" in store) resolvedStore = await store.resolver(this.app);
|
|
12
|
+
else resolvedStore = store;
|
|
13
|
+
return [name, resolvedStore];
|
|
14
|
+
});
|
|
15
|
+
return new Verrou({
|
|
16
|
+
default: config.default,
|
|
17
|
+
stores: Object.fromEntries(await Promise.all(stores))
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
}
|
|
33
21
|
};
|
|
22
|
+
export { LockProvider as default };
|
package/build/services/main.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { LockService } from '../src/types.ts';
|
|
2
|
-
declare let
|
|
3
|
-
export {
|
|
2
|
+
declare let lockManager: LockService;
|
|
3
|
+
export { lockManager as default };
|
package/build/services/main.js
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
import "../chunk-MLKGABMK.js";
|
|
2
|
-
|
|
3
|
-
// services/main.ts
|
|
4
1
|
import app from "@adonisjs/core/services/app";
|
|
5
|
-
|
|
2
|
+
let lockManager;
|
|
6
3
|
await app.booted(async () => {
|
|
7
|
-
|
|
4
|
+
lockManager = await app.container.make("lock.manager");
|
|
8
5
|
});
|
|
9
|
-
export {
|
|
10
|
-
lock as default
|
|
11
|
-
};
|
|
6
|
+
export { lockManager as default };
|
package/build/src/types.js
CHANGED
package/build/tests/helpers.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Database } from '@adonisjs/lucid/database';
|
|
2
2
|
import { type RedisConnection, RedisManager } from '@adonisjs/redis';
|
|
3
3
|
import { IgnitorFactory } from '@adonisjs/core/factories/core/ignitor';
|
|
4
|
-
export declare const BASE_URL: import("url").URL;
|
|
4
|
+
export declare const BASE_URL: import("node:url").URL;
|
|
5
5
|
export declare const IMPORTER: (filePath: string) => Promise<any>;
|
|
6
6
|
/**
|
|
7
7
|
* Setup an AdonisJS app for testing
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adonisjs/lock",
|
|
3
3
|
"description": "Atomic locks (mutex) for AdonisJS applications",
|
|
4
|
-
"version": "2.0.0",
|
|
4
|
+
"version": "2.1.0-next.0",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=22"
|
|
7
7
|
},
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"pretest": "npm run lint",
|
|
26
26
|
"test": "c8 npm run quick:test",
|
|
27
27
|
"prebuild": "npm run lint && npm run clean",
|
|
28
|
-
"compile": "
|
|
29
|
-
"build": "
|
|
28
|
+
"compile": "tsdown && tsc --emitDeclarationOnly --declaration",
|
|
29
|
+
"build": "tsdown && tsc --emitDeclarationOnly --declaration && npm run copy:templates",
|
|
30
30
|
"release": "npx release-it",
|
|
31
31
|
"version": "npm run build",
|
|
32
32
|
"prepublishOnly": "npm run build"
|
|
@@ -34,31 +34,30 @@
|
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@adonisjs/assembler": "^8.0.0-next.19",
|
|
36
36
|
"@adonisjs/core": "^7.0.0-next.13",
|
|
37
|
-
"@adonisjs/eslint-config": "^3.0.0-next.
|
|
37
|
+
"@adonisjs/eslint-config": "^3.0.0-next.9",
|
|
38
38
|
"@adonisjs/lucid": "^22.0.0-next.1",
|
|
39
39
|
"@adonisjs/prettier-config": "^1.4.5",
|
|
40
40
|
"@adonisjs/redis": "^10.0.0-next.1",
|
|
41
41
|
"@adonisjs/tsconfig": "^2.0.0-next.3",
|
|
42
|
-
"@japa/assert": "^4.
|
|
43
|
-
"@japa/file-system": "^
|
|
44
|
-
"@japa/runner": "^
|
|
45
|
-
"@poppinss/ts-exec": "^1.4.
|
|
46
|
-
"@release-it/conventional-changelog": "^10.0.
|
|
47
|
-
"@
|
|
48
|
-
"
|
|
49
|
-
"better-sqlite3": "^12.5.0",
|
|
42
|
+
"@japa/assert": "^4.2.0",
|
|
43
|
+
"@japa/file-system": "^3.0.0",
|
|
44
|
+
"@japa/runner": "^5.3.0",
|
|
45
|
+
"@poppinss/ts-exec": "^1.4.3",
|
|
46
|
+
"@release-it/conventional-changelog": "^10.0.4",
|
|
47
|
+
"@types/node": "^25.2.0",
|
|
48
|
+
"better-sqlite3": "^12.6.2",
|
|
50
49
|
"c8": "^10.1.3",
|
|
51
50
|
"copyfiles": "^2.4.1",
|
|
52
51
|
"del-cli": "^7.0.0",
|
|
53
52
|
"dotenv": "^17.2.3",
|
|
54
|
-
"eslint": "^9.39.
|
|
53
|
+
"eslint": "^9.39.2",
|
|
55
54
|
"luxon": "^3.7.2",
|
|
56
55
|
"mysql": "^2.18.1",
|
|
57
|
-
"pg": "^8.
|
|
58
|
-
"prettier": "^3.
|
|
59
|
-
"release-it": "^19.
|
|
56
|
+
"pg": "^8.18.0",
|
|
57
|
+
"prettier": "^3.8.1",
|
|
58
|
+
"release-it": "^19.2.4",
|
|
60
59
|
"timekeeper": "^2.3.1",
|
|
61
|
-
"
|
|
60
|
+
"tsdown": "^0.20.1",
|
|
62
61
|
"typescript": "^5.9.3"
|
|
63
62
|
},
|
|
64
63
|
"dependencies": {
|
|
@@ -136,7 +135,7 @@
|
|
|
136
135
|
"tests_helpers/**"
|
|
137
136
|
]
|
|
138
137
|
},
|
|
139
|
-
"
|
|
138
|
+
"tsdown": {
|
|
140
139
|
"entry": [
|
|
141
140
|
"./index.ts",
|
|
142
141
|
"./src/types.ts",
|
|
@@ -146,7 +145,11 @@
|
|
|
146
145
|
"outDir": "./build",
|
|
147
146
|
"clean": true,
|
|
148
147
|
"format": "esm",
|
|
148
|
+
"minify": "dce-only",
|
|
149
|
+
"fixedExtension": false,
|
|
149
150
|
"dts": false,
|
|
151
|
+
"treeshake": false,
|
|
152
|
+
"sourcemaps": false,
|
|
150
153
|
"target": "esnext"
|
|
151
154
|
}
|
|
152
155
|
}
|