@meridianjs/user 0.1.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/dist/index.d.mts +19 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +120 -0
- package/dist/index.mjs +94 -0
- package/package.json +44 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as _meridianjs_types from '@meridianjs/types';
|
|
2
|
+
import { MeridianContainer } from '@meridianjs/types';
|
|
3
|
+
|
|
4
|
+
declare const UserModuleService_base: new (container: MeridianContainer) => _meridianjs_types.IModuleService;
|
|
5
|
+
declare class UserModuleService extends UserModuleService_base {
|
|
6
|
+
private readonly container;
|
|
7
|
+
constructor(container: MeridianContainer);
|
|
8
|
+
/** Find a user by email. Returns null if not found. */
|
|
9
|
+
retrieveUserByEmail(email: string): Promise<any | null>;
|
|
10
|
+
/** Update user's last login timestamp. */
|
|
11
|
+
recordLogin(userId: string): Promise<void>;
|
|
12
|
+
/** Deactivate a user account. */
|
|
13
|
+
deactivateUser(userId: string): Promise<any>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
declare const USER_MODULE = "userModuleService";
|
|
17
|
+
declare const _default: _meridianjs_types.ModuleDefinition;
|
|
18
|
+
|
|
19
|
+
export { UserModuleService as IUserModuleService, USER_MODULE, UserModuleService, _default as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as _meridianjs_types from '@meridianjs/types';
|
|
2
|
+
import { MeridianContainer } from '@meridianjs/types';
|
|
3
|
+
|
|
4
|
+
declare const UserModuleService_base: new (container: MeridianContainer) => _meridianjs_types.IModuleService;
|
|
5
|
+
declare class UserModuleService extends UserModuleService_base {
|
|
6
|
+
private readonly container;
|
|
7
|
+
constructor(container: MeridianContainer);
|
|
8
|
+
/** Find a user by email. Returns null if not found. */
|
|
9
|
+
retrieveUserByEmail(email: string): Promise<any | null>;
|
|
10
|
+
/** Update user's last login timestamp. */
|
|
11
|
+
recordLogin(userId: string): Promise<void>;
|
|
12
|
+
/** Deactivate a user account. */
|
|
13
|
+
deactivateUser(userId: string): Promise<any>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
declare const USER_MODULE = "userModuleService";
|
|
17
|
+
declare const _default: _meridianjs_types.ModuleDefinition;
|
|
18
|
+
|
|
19
|
+
export { UserModuleService as IUserModuleService, USER_MODULE, UserModuleService, _default as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
USER_MODULE: () => USER_MODULE,
|
|
24
|
+
UserModuleService: () => UserModuleService,
|
|
25
|
+
default: () => index_default
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(index_exports);
|
|
28
|
+
var import_framework_utils5 = require("@meridianjs/framework-utils");
|
|
29
|
+
|
|
30
|
+
// src/service.ts
|
|
31
|
+
var import_framework_utils3 = require("@meridianjs/framework-utils");
|
|
32
|
+
|
|
33
|
+
// src/models/user.ts
|
|
34
|
+
var import_framework_utils = require("@meridianjs/framework-utils");
|
|
35
|
+
var User = import_framework_utils.model.define("user", {
|
|
36
|
+
id: import_framework_utils.model.id().primaryKey(),
|
|
37
|
+
email: import_framework_utils.model.text(),
|
|
38
|
+
password_hash: import_framework_utils.model.text(),
|
|
39
|
+
first_name: import_framework_utils.model.text().nullable(),
|
|
40
|
+
last_name: import_framework_utils.model.text().nullable(),
|
|
41
|
+
avatar_url: import_framework_utils.model.text().nullable(),
|
|
42
|
+
is_active: import_framework_utils.model.boolean().default(true),
|
|
43
|
+
last_login_at: import_framework_utils.model.date().nullable(),
|
|
44
|
+
metadata: import_framework_utils.model.json().nullable()
|
|
45
|
+
}, [
|
|
46
|
+
{ columns: ["email"], unique: true }
|
|
47
|
+
]);
|
|
48
|
+
var user_default = User;
|
|
49
|
+
|
|
50
|
+
// src/models/team.ts
|
|
51
|
+
var import_framework_utils2 = require("@meridianjs/framework-utils");
|
|
52
|
+
var Team = import_framework_utils2.model.define("team", {
|
|
53
|
+
id: import_framework_utils2.model.id().primaryKey(),
|
|
54
|
+
name: import_framework_utils2.model.text(),
|
|
55
|
+
workspace_id: import_framework_utils2.model.text(),
|
|
56
|
+
description: import_framework_utils2.model.text().nullable(),
|
|
57
|
+
icon: import_framework_utils2.model.text().nullable()
|
|
58
|
+
});
|
|
59
|
+
var team_default = Team;
|
|
60
|
+
|
|
61
|
+
// src/service.ts
|
|
62
|
+
var UserModuleService = class extends (0, import_framework_utils3.MeridianService)({ User: user_default, Team: team_default }) {
|
|
63
|
+
// Subclasses store their own container reference for custom methods
|
|
64
|
+
container;
|
|
65
|
+
constructor(container) {
|
|
66
|
+
super(container);
|
|
67
|
+
this.container = container;
|
|
68
|
+
}
|
|
69
|
+
/** Find a user by email. Returns null if not found. */
|
|
70
|
+
async retrieveUserByEmail(email) {
|
|
71
|
+
const userRepository = this.container.resolve("userRepository");
|
|
72
|
+
try {
|
|
73
|
+
return await userRepository.findOneOrFail({ email });
|
|
74
|
+
} catch {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/** Update user's last login timestamp. */
|
|
79
|
+
async recordLogin(userId) {
|
|
80
|
+
await this.updateUser(userId, { last_login_at: /* @__PURE__ */ new Date() });
|
|
81
|
+
}
|
|
82
|
+
/** Deactivate a user account. */
|
|
83
|
+
async deactivateUser(userId) {
|
|
84
|
+
return this.updateUser(userId, { is_active: false });
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
// src/loaders/default.ts
|
|
89
|
+
var import_framework_utils4 = require("@meridianjs/framework-utils");
|
|
90
|
+
var UserSchema = (0, import_framework_utils4.dmlToEntitySchema)(user_default);
|
|
91
|
+
var TeamSchema = (0, import_framework_utils4.dmlToEntitySchema)(team_default);
|
|
92
|
+
var entitySchemas = [UserSchema, TeamSchema];
|
|
93
|
+
async function defaultLoader({ container }) {
|
|
94
|
+
const config = container.resolve("config");
|
|
95
|
+
const { databaseUrl } = config.projectConfig;
|
|
96
|
+
const orm = await (0, import_framework_utils4.createModuleOrm)(entitySchemas, databaseUrl);
|
|
97
|
+
const em = orm.em.fork();
|
|
98
|
+
container.register({
|
|
99
|
+
userRepository: (0, import_framework_utils4.createRepository)(em, "user"),
|
|
100
|
+
teamRepository: (0, import_framework_utils4.createRepository)(em, "team"),
|
|
101
|
+
userOrm: orm
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// src/index.ts
|
|
106
|
+
var USER_MODULE = "userModuleService";
|
|
107
|
+
var index_default = (0, import_framework_utils5.Module)(USER_MODULE, {
|
|
108
|
+
service: UserModuleService,
|
|
109
|
+
models: [user_default, team_default],
|
|
110
|
+
loaders: [defaultLoader],
|
|
111
|
+
linkable: {
|
|
112
|
+
user: { tableName: "user", primaryKey: "id" },
|
|
113
|
+
team: { tableName: "team", primaryKey: "id" }
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
117
|
+
0 && (module.exports = {
|
|
118
|
+
USER_MODULE,
|
|
119
|
+
UserModuleService
|
|
120
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { Module } from "@meridianjs/framework-utils";
|
|
3
|
+
|
|
4
|
+
// src/service.ts
|
|
5
|
+
import { MeridianService } from "@meridianjs/framework-utils";
|
|
6
|
+
|
|
7
|
+
// src/models/user.ts
|
|
8
|
+
import { model } from "@meridianjs/framework-utils";
|
|
9
|
+
var User = model.define("user", {
|
|
10
|
+
id: model.id().primaryKey(),
|
|
11
|
+
email: model.text(),
|
|
12
|
+
password_hash: model.text(),
|
|
13
|
+
first_name: model.text().nullable(),
|
|
14
|
+
last_name: model.text().nullable(),
|
|
15
|
+
avatar_url: model.text().nullable(),
|
|
16
|
+
is_active: model.boolean().default(true),
|
|
17
|
+
last_login_at: model.date().nullable(),
|
|
18
|
+
metadata: model.json().nullable()
|
|
19
|
+
}, [
|
|
20
|
+
{ columns: ["email"], unique: true }
|
|
21
|
+
]);
|
|
22
|
+
var user_default = User;
|
|
23
|
+
|
|
24
|
+
// src/models/team.ts
|
|
25
|
+
import { model as model2 } from "@meridianjs/framework-utils";
|
|
26
|
+
var Team = model2.define("team", {
|
|
27
|
+
id: model2.id().primaryKey(),
|
|
28
|
+
name: model2.text(),
|
|
29
|
+
workspace_id: model2.text(),
|
|
30
|
+
description: model2.text().nullable(),
|
|
31
|
+
icon: model2.text().nullable()
|
|
32
|
+
});
|
|
33
|
+
var team_default = Team;
|
|
34
|
+
|
|
35
|
+
// src/service.ts
|
|
36
|
+
var UserModuleService = class extends MeridianService({ User: user_default, Team: team_default }) {
|
|
37
|
+
// Subclasses store their own container reference for custom methods
|
|
38
|
+
container;
|
|
39
|
+
constructor(container) {
|
|
40
|
+
super(container);
|
|
41
|
+
this.container = container;
|
|
42
|
+
}
|
|
43
|
+
/** Find a user by email. Returns null if not found. */
|
|
44
|
+
async retrieveUserByEmail(email) {
|
|
45
|
+
const userRepository = this.container.resolve("userRepository");
|
|
46
|
+
try {
|
|
47
|
+
return await userRepository.findOneOrFail({ email });
|
|
48
|
+
} catch {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/** Update user's last login timestamp. */
|
|
53
|
+
async recordLogin(userId) {
|
|
54
|
+
await this.updateUser(userId, { last_login_at: /* @__PURE__ */ new Date() });
|
|
55
|
+
}
|
|
56
|
+
/** Deactivate a user account. */
|
|
57
|
+
async deactivateUser(userId) {
|
|
58
|
+
return this.updateUser(userId, { is_active: false });
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// src/loaders/default.ts
|
|
63
|
+
import { dmlToEntitySchema, createRepository, createModuleOrm } from "@meridianjs/framework-utils";
|
|
64
|
+
var UserSchema = dmlToEntitySchema(user_default);
|
|
65
|
+
var TeamSchema = dmlToEntitySchema(team_default);
|
|
66
|
+
var entitySchemas = [UserSchema, TeamSchema];
|
|
67
|
+
async function defaultLoader({ container }) {
|
|
68
|
+
const config = container.resolve("config");
|
|
69
|
+
const { databaseUrl } = config.projectConfig;
|
|
70
|
+
const orm = await createModuleOrm(entitySchemas, databaseUrl);
|
|
71
|
+
const em = orm.em.fork();
|
|
72
|
+
container.register({
|
|
73
|
+
userRepository: createRepository(em, "user"),
|
|
74
|
+
teamRepository: createRepository(em, "team"),
|
|
75
|
+
userOrm: orm
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// src/index.ts
|
|
80
|
+
var USER_MODULE = "userModuleService";
|
|
81
|
+
var index_default = Module(USER_MODULE, {
|
|
82
|
+
service: UserModuleService,
|
|
83
|
+
models: [user_default, team_default],
|
|
84
|
+
loaders: [defaultLoader],
|
|
85
|
+
linkable: {
|
|
86
|
+
user: { tableName: "user", primaryKey: "id" },
|
|
87
|
+
team: { tableName: "team", primaryKey: "id" }
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
export {
|
|
91
|
+
USER_MODULE,
|
|
92
|
+
UserModuleService,
|
|
93
|
+
index_default as default
|
|
94
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@meridianjs/user",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Meridian user module — User and Team domain models",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": {
|
|
11
|
+
"types": "./dist/index.d.mts",
|
|
12
|
+
"default": "./dist/index.mjs"
|
|
13
|
+
},
|
|
14
|
+
"require": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"default": "./dist/index.js"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsup src/index.ts --format esm,cjs --dts --clean",
|
|
22
|
+
"dev": "tsup src/index.ts --format esm,cjs --dts --watch",
|
|
23
|
+
"typecheck": "tsc --noEmit",
|
|
24
|
+
"clean": "rm -rf dist",
|
|
25
|
+
"prepublishOnly": "npm run build"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@meridianjs/framework-utils": "^0.1.0",
|
|
29
|
+
"@meridianjs/types": "^0.1.0",
|
|
30
|
+
"@mikro-orm/core": "^6.4.3",
|
|
31
|
+
"@mikro-orm/postgresql": "^6.4.3",
|
|
32
|
+
"@mikro-orm/migrations": "^6.4.3"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"tsup": "^8.3.5",
|
|
36
|
+
"typescript": "*"
|
|
37
|
+
},
|
|
38
|
+
"files": [
|
|
39
|
+
"dist"
|
|
40
|
+
],
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
}
|
|
44
|
+
}
|