@spinajs/session-provider-db 2.0.487 → 2.0.489

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 (23) hide show
  1. package/lib/cjs/index.d.ts +1 -1
  2. package/lib/cjs/index.js +1 -1
  3. package/lib/cjs/migrations/UserSessionDBSqlMigration_2022_06_28_01_20_00.d.ts +28 -0
  4. package/lib/cjs/migrations/UserSessionDBSqlMigration_2022_06_28_01_20_00.d.ts.map +1 -0
  5. package/lib/cjs/migrations/UserSessionDBSqlMigration_2022_06_28_01_20_00.js +58 -0
  6. package/lib/cjs/migrations/UserSessionDBSqlMigration_2022_06_28_01_20_00.js.map +1 -0
  7. package/lib/mjs/index.d.ts +1 -1
  8. package/lib/mjs/index.js +1 -1
  9. package/lib/mjs/migrations/UserSessionDBSqlMigration_2022_06_28_01_20_00.d.ts +28 -0
  10. package/lib/mjs/migrations/UserSessionDBSqlMigration_2022_06_28_01_20_00.d.ts.map +1 -0
  11. package/lib/mjs/migrations/UserSessionDBSqlMigration_2022_06_28_01_20_00.js +55 -0
  12. package/lib/mjs/migrations/UserSessionDBSqlMigration_2022_06_28_01_20_00.js.map +1 -0
  13. package/lib/tsconfig.cjs.tsbuildinfo +1 -1
  14. package/lib/tsconfig.mjs.tsbuildinfo +1 -1
  15. package/package.json +10 -10
  16. package/lib/cjs/migrations/UserSessionDBSqlMigration_2022_06_28_01_01_01.d.ts +0 -6
  17. package/lib/cjs/migrations/UserSessionDBSqlMigration_2022_06_28_01_01_01.d.ts.map +0 -1
  18. package/lib/cjs/migrations/UserSessionDBSqlMigration_2022_06_28_01_01_01.js +0 -31
  19. package/lib/cjs/migrations/UserSessionDBSqlMigration_2022_06_28_01_01_01.js.map +0 -1
  20. package/lib/mjs/migrations/UserSessionDBSqlMigration_2022_06_28_01_01_01.d.ts +0 -6
  21. package/lib/mjs/migrations/UserSessionDBSqlMigration_2022_06_28_01_01_01.d.ts.map +0 -1
  22. package/lib/mjs/migrations/UserSessionDBSqlMigration_2022_06_28_01_01_01.js +0 -28
  23. package/lib/mjs/migrations/UserSessionDBSqlMigration_2022_06_28_01_01_01.js.map +0 -1
@@ -1,7 +1,7 @@
1
1
  import { SessionProvider, ISession } from '@spinajs/rbac';
2
2
  import { Log } from '@spinajs/log';
3
3
  export * from './models/DbSession.js';
4
- export * from './migrations/UserSessionDBSqlMigration_2022_06_28_01_01_01.js';
4
+ export * from './migrations/UserSessionDBSqlMigration_2022_06_28_01_20_00.js';
5
5
  /**
6
6
  * Relational-db backed session store. Conforms to the `@spinajs/rbac`
7
7
  * `SessionProvider` contract: ownership is the numeric `UserId`, expiration is
package/lib/cjs/index.js CHANGED
@@ -32,7 +32,7 @@ const orm_1 = require("@spinajs/orm");
32
32
  const configuration_1 = require("@spinajs/configuration");
33
33
  const luxon_1 = require("luxon");
34
34
  __exportStar(require("./models/DbSession.js"), exports);
35
- __exportStar(require("./migrations/UserSessionDBSqlMigration_2022_06_28_01_01_01.js"), exports);
35
+ __exportStar(require("./migrations/UserSessionDBSqlMigration_2022_06_28_01_20_00.js"), exports);
36
36
  /**
37
37
  * Relational-db backed session store. Conforms to the `@spinajs/rbac`
38
38
  * `SessionProvider` contract: ownership is the numeric `UserId`, expiration is
@@ -0,0 +1,28 @@
1
+ import { OrmMigration, OrmDriver } from '@spinajs/orm';
2
+ /**
3
+ * Creates the `user_sessions` table.
4
+ *
5
+ * The timestamp is deliberately later than `@spinajs/rbac`'s `RBACInitial_2022_06_28_01_13_00`,
6
+ * because the foreign key below references `users`, which that migration creates. When
7
+ * `session-provider-connection` is an alias of the default connection - the usual setup, and what
8
+ * `db.Aliases` exists for - both migrations resolve to the same `OrmDriver`, so
9
+ * `MigrationRunner.plan()` collapses them into one group and runs them in timestamp order. This
10
+ * migration previously carried the timestamp `2022_06_28_01_01_01`, twelve minutes *before*
11
+ * `RBACInitial`, so on an empty database it ran first and failed with `ER_FK_CANNOT_OPEN_PARENT` -
12
+ * the parent table did not exist yet.
13
+ *
14
+ * Renaming a migration is normally unsafe, because the applied-migration row records the class name
15
+ * and a renamed class looks like a new, unapplied one. Two things make it safe here:
16
+ *
17
+ * - the migration service builds its pending list as registered-minus-applied and never looks an
18
+ * applied row up in the registry, so the row left behind under the old name is simply ignored
19
+ * - the guard below makes a re-run a no-op, so a database that already has the table records this
20
+ * migration as applied without touching anything
21
+ *
22
+ * No `migration resolve` step is therefore needed on existing deployments.
23
+ */
24
+ export declare class UserSessionDBSqlMigration_2022_06_28_01_20_00 extends OrmMigration {
25
+ up(connection: OrmDriver): Promise<void>;
26
+ down(_: OrmDriver): Promise<void>;
27
+ }
28
+ //# sourceMappingURL=UserSessionDBSqlMigration_2022_06_28_01_20_00.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UserSessionDBSqlMigration_2022_06_28_01_20_00.d.ts","sourceRoot":"","sources":["../../../src/migrations/UserSessionDBSqlMigration_2022_06_28_01_20_00.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,YAAY,EAAE,SAAS,EAAqB,MAAM,cAAc,CAAC;AAErF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBACa,6CAA8C,SAAQ,YAAY;IAChE,EAAE,CAAC,UAAU,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IAsBxC,IAAI,CAAC,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;CAC/C"}
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.UserSessionDBSqlMigration_2022_06_28_01_20_00 = void 0;
10
+ const orm_1 = require("@spinajs/orm");
11
+ /**
12
+ * Creates the `user_sessions` table.
13
+ *
14
+ * The timestamp is deliberately later than `@spinajs/rbac`'s `RBACInitial_2022_06_28_01_13_00`,
15
+ * because the foreign key below references `users`, which that migration creates. When
16
+ * `session-provider-connection` is an alias of the default connection - the usual setup, and what
17
+ * `db.Aliases` exists for - both migrations resolve to the same `OrmDriver`, so
18
+ * `MigrationRunner.plan()` collapses them into one group and runs them in timestamp order. This
19
+ * migration previously carried the timestamp `2022_06_28_01_01_01`, twelve minutes *before*
20
+ * `RBACInitial`, so on an empty database it ran first and failed with `ER_FK_CANNOT_OPEN_PARENT` -
21
+ * the parent table did not exist yet.
22
+ *
23
+ * Renaming a migration is normally unsafe, because the applied-migration row records the class name
24
+ * and a renamed class looks like a new, unapplied one. Two things make it safe here:
25
+ *
26
+ * - the migration service builds its pending list as registered-minus-applied and never looks an
27
+ * applied row up in the registry, so the row left behind under the old name is simply ignored
28
+ * - the guard below makes a re-run a no-op, so a database that already has the table records this
29
+ * migration as applied without touching anything
30
+ *
31
+ * No `migration resolve` step is therefore needed on existing deployments.
32
+ */
33
+ let UserSessionDBSqlMigration_2022_06_28_01_20_00 = class UserSessionDBSqlMigration_2022_06_28_01_20_00 extends orm_1.OrmMigration {
34
+ async up(connection) {
35
+ // Databases that applied this migration under its old name already have the table. Returning
36
+ // here is what lets the rename cost nothing on an existing deployment.
37
+ if (await connection.schema().tableExists('user_sessions')) {
38
+ return;
39
+ }
40
+ await connection.schema().createTable('user_sessions', (table) => {
41
+ table.string('SessionId', 36).primaryKey().notNull();
42
+ table.dateTime('CreatedAt').notNull();
43
+ table.dateTime('Expiration');
44
+ table.json('Data').notNull();
45
+ table.int('UserId').notNull();
46
+ table.foreignKey('UserId').references('users', 'Id').onDelete(orm_1.ReferentialAction.Cascade);
47
+ });
48
+ // create index explicit, otherwise sqlite driver cannot extract unique index from sqlite_master
49
+ await connection.index().table('user_sessions').name('session_id_user_session_idx').columns(['SessionId']).unique();
50
+ }
51
+ // tslint:disable-next-line: no-empty
52
+ async down(_) { }
53
+ };
54
+ exports.UserSessionDBSqlMigration_2022_06_28_01_20_00 = UserSessionDBSqlMigration_2022_06_28_01_20_00;
55
+ exports.UserSessionDBSqlMigration_2022_06_28_01_20_00 = UserSessionDBSqlMigration_2022_06_28_01_20_00 = __decorate([
56
+ (0, orm_1.Migration)('session-provider-connection')
57
+ ], UserSessionDBSqlMigration_2022_06_28_01_20_00);
58
+ //# sourceMappingURL=UserSessionDBSqlMigration_2022_06_28_01_20_00.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UserSessionDBSqlMigration_2022_06_28_01_20_00.js","sourceRoot":"","sources":["../../../src/migrations/UserSessionDBSqlMigration_2022_06_28_01_20_00.ts"],"names":[],"mappings":";;;;;;;;;AAAA,sCAAqF;AAErF;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEI,IAAM,6CAA6C,GAAnD,MAAM,6CAA8C,SAAQ,kBAAY;IACtE,KAAK,CAAC,EAAE,CAAC,UAAqB;QACnC,6FAA6F;QAC7F,uEAAuE;QACvE,IAAI,MAAM,UAAU,CAAC,MAAM,EAAE,CAAC,WAAW,CAAC,eAAe,CAAC,EAAE,CAAC;YAC3D,OAAO;QACT,CAAC;QAED,MAAM,UAAU,CAAC,MAAM,EAAE,CAAC,WAAW,CAAC,eAAe,EAAE,CAAC,KAAK,EAAE,EAAE;YAC/D,KAAK,CAAC,MAAM,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,UAAU,EAAE,CAAC,OAAO,EAAE,CAAC;YACrD,KAAK,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,OAAO,EAAE,CAAC;YACtC,KAAK,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;YAC7B,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,CAAC;YAC7B,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,OAAO,EAAE,CAAC;YAE9B,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,QAAQ,CAAC,uBAAiB,CAAC,OAAO,CAAC,CAAC;QAC3F,CAAC,CAAC,CAAC;QAEH,gGAAgG;QAChG,MAAM,UAAU,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC,OAAO,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IACtH,CAAC;IAED,qCAAqC;IAC9B,KAAK,CAAC,IAAI,CAAC,CAAY,IAAkB,CAAC;CAClD,CAAA;AAxBY,sGAA6C;wDAA7C,6CAA6C;IADzD,IAAA,eAAS,EAAC,6BAA6B,CAAC;GAC5B,6CAA6C,CAwBzD"}
@@ -1,7 +1,7 @@
1
1
  import { SessionProvider, ISession } from '@spinajs/rbac';
2
2
  import { Log } from '@spinajs/log';
3
3
  export * from './models/DbSession.js';
4
- export * from './migrations/UserSessionDBSqlMigration_2022_06_28_01_01_01.js';
4
+ export * from './migrations/UserSessionDBSqlMigration_2022_06_28_01_20_00.js';
5
5
  /**
6
6
  * Relational-db backed session store. Conforms to the `@spinajs/rbac`
7
7
  * `SessionProvider` contract: ownership is the numeric `UserId`, expiration is
package/lib/mjs/index.js CHANGED
@@ -15,7 +15,7 @@ import { InsertBehaviour } from '@spinajs/orm';
15
15
  import { Config } from '@spinajs/configuration';
16
16
  import { DateTime } from 'luxon';
17
17
  export * from './models/DbSession.js';
18
- export * from './migrations/UserSessionDBSqlMigration_2022_06_28_01_01_01.js';
18
+ export * from './migrations/UserSessionDBSqlMigration_2022_06_28_01_20_00.js';
19
19
  /**
20
20
  * Relational-db backed session store. Conforms to the `@spinajs/rbac`
21
21
  * `SessionProvider` contract: ownership is the numeric `UserId`, expiration is
@@ -0,0 +1,28 @@
1
+ import { OrmMigration, OrmDriver } from '@spinajs/orm';
2
+ /**
3
+ * Creates the `user_sessions` table.
4
+ *
5
+ * The timestamp is deliberately later than `@spinajs/rbac`'s `RBACInitial_2022_06_28_01_13_00`,
6
+ * because the foreign key below references `users`, which that migration creates. When
7
+ * `session-provider-connection` is an alias of the default connection - the usual setup, and what
8
+ * `db.Aliases` exists for - both migrations resolve to the same `OrmDriver`, so
9
+ * `MigrationRunner.plan()` collapses them into one group and runs them in timestamp order. This
10
+ * migration previously carried the timestamp `2022_06_28_01_01_01`, twelve minutes *before*
11
+ * `RBACInitial`, so on an empty database it ran first and failed with `ER_FK_CANNOT_OPEN_PARENT` -
12
+ * the parent table did not exist yet.
13
+ *
14
+ * Renaming a migration is normally unsafe, because the applied-migration row records the class name
15
+ * and a renamed class looks like a new, unapplied one. Two things make it safe here:
16
+ *
17
+ * - the migration service builds its pending list as registered-minus-applied and never looks an
18
+ * applied row up in the registry, so the row left behind under the old name is simply ignored
19
+ * - the guard below makes a re-run a no-op, so a database that already has the table records this
20
+ * migration as applied without touching anything
21
+ *
22
+ * No `migration resolve` step is therefore needed on existing deployments.
23
+ */
24
+ export declare class UserSessionDBSqlMigration_2022_06_28_01_20_00 extends OrmMigration {
25
+ up(connection: OrmDriver): Promise<void>;
26
+ down(_: OrmDriver): Promise<void>;
27
+ }
28
+ //# sourceMappingURL=UserSessionDBSqlMigration_2022_06_28_01_20_00.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UserSessionDBSqlMigration_2022_06_28_01_20_00.d.ts","sourceRoot":"","sources":["../../../src/migrations/UserSessionDBSqlMigration_2022_06_28_01_20_00.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,YAAY,EAAE,SAAS,EAAqB,MAAM,cAAc,CAAC;AAErF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBACa,6CAA8C,SAAQ,YAAY;IAChE,EAAE,CAAC,UAAU,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IAsBxC,IAAI,CAAC,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;CAC/C"}
@@ -0,0 +1,55 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { Migration, OrmMigration, ReferentialAction } from '@spinajs/orm';
8
+ /**
9
+ * Creates the `user_sessions` table.
10
+ *
11
+ * The timestamp is deliberately later than `@spinajs/rbac`'s `RBACInitial_2022_06_28_01_13_00`,
12
+ * because the foreign key below references `users`, which that migration creates. When
13
+ * `session-provider-connection` is an alias of the default connection - the usual setup, and what
14
+ * `db.Aliases` exists for - both migrations resolve to the same `OrmDriver`, so
15
+ * `MigrationRunner.plan()` collapses them into one group and runs them in timestamp order. This
16
+ * migration previously carried the timestamp `2022_06_28_01_01_01`, twelve minutes *before*
17
+ * `RBACInitial`, so on an empty database it ran first and failed with `ER_FK_CANNOT_OPEN_PARENT` -
18
+ * the parent table did not exist yet.
19
+ *
20
+ * Renaming a migration is normally unsafe, because the applied-migration row records the class name
21
+ * and a renamed class looks like a new, unapplied one. Two things make it safe here:
22
+ *
23
+ * - the migration service builds its pending list as registered-minus-applied and never looks an
24
+ * applied row up in the registry, so the row left behind under the old name is simply ignored
25
+ * - the guard below makes a re-run a no-op, so a database that already has the table records this
26
+ * migration as applied without touching anything
27
+ *
28
+ * No `migration resolve` step is therefore needed on existing deployments.
29
+ */
30
+ let UserSessionDBSqlMigration_2022_06_28_01_20_00 = class UserSessionDBSqlMigration_2022_06_28_01_20_00 extends OrmMigration {
31
+ async up(connection) {
32
+ // Databases that applied this migration under its old name already have the table. Returning
33
+ // here is what lets the rename cost nothing on an existing deployment.
34
+ if (await connection.schema().tableExists('user_sessions')) {
35
+ return;
36
+ }
37
+ await connection.schema().createTable('user_sessions', (table) => {
38
+ table.string('SessionId', 36).primaryKey().notNull();
39
+ table.dateTime('CreatedAt').notNull();
40
+ table.dateTime('Expiration');
41
+ table.json('Data').notNull();
42
+ table.int('UserId').notNull();
43
+ table.foreignKey('UserId').references('users', 'Id').onDelete(ReferentialAction.Cascade);
44
+ });
45
+ // create index explicit, otherwise sqlite driver cannot extract unique index from sqlite_master
46
+ await connection.index().table('user_sessions').name('session_id_user_session_idx').columns(['SessionId']).unique();
47
+ }
48
+ // tslint:disable-next-line: no-empty
49
+ async down(_) { }
50
+ };
51
+ UserSessionDBSqlMigration_2022_06_28_01_20_00 = __decorate([
52
+ Migration('session-provider-connection')
53
+ ], UserSessionDBSqlMigration_2022_06_28_01_20_00);
54
+ export { UserSessionDBSqlMigration_2022_06_28_01_20_00 };
55
+ //# sourceMappingURL=UserSessionDBSqlMigration_2022_06_28_01_20_00.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UserSessionDBSqlMigration_2022_06_28_01_20_00.js","sourceRoot":"","sources":["../../../src/migrations/UserSessionDBSqlMigration_2022_06_28_01_20_00.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAa,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAErF;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEI,IAAM,6CAA6C,GAAnD,MAAM,6CAA8C,SAAQ,YAAY;IACtE,KAAK,CAAC,EAAE,CAAC,UAAqB;QACnC,6FAA6F;QAC7F,uEAAuE;QACvE,IAAI,MAAM,UAAU,CAAC,MAAM,EAAE,CAAC,WAAW,CAAC,eAAe,CAAC,EAAE,CAAC;YAC3D,OAAO;QACT,CAAC;QAED,MAAM,UAAU,CAAC,MAAM,EAAE,CAAC,WAAW,CAAC,eAAe,EAAE,CAAC,KAAK,EAAE,EAAE;YAC/D,KAAK,CAAC,MAAM,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,UAAU,EAAE,CAAC,OAAO,EAAE,CAAC;YACrD,KAAK,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,OAAO,EAAE,CAAC;YACtC,KAAK,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;YAC7B,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,CAAC;YAC7B,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,OAAO,EAAE,CAAC;YAE9B,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,QAAQ,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;QAC3F,CAAC,CAAC,CAAC;QAEH,gGAAgG;QAChG,MAAM,UAAU,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC,OAAO,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IACtH,CAAC;IAED,qCAAqC;IAC9B,KAAK,CAAC,IAAI,CAAC,CAAY,IAAkB,CAAC;CAClD,CAAA;AAxBY,6CAA6C;IADzD,SAAS,CAAC,6BAA6B,CAAC;GAC5B,6CAA6C,CAwBzD"}