@pwrdrvr/microapps-datalib 0.0.15 → 0.0.19
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.ts +5 -23
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -48
- package/dist/index.js.map +1 -1
- package/dist/manager.d.ts +20 -0
- package/dist/manager.d.ts.map +1 -0
- package/dist/manager.js +26 -0
- package/dist/manager.js.map +1 -0
- package/dist/models/application.d.ts +22 -5
- package/dist/models/application.d.ts.map +1 -1
- package/dist/models/application.js +37 -14
- package/dist/models/application.js.map +1 -1
- package/dist/models/rules.d.ts +8 -4
- package/dist/models/rules.d.ts.map +1 -1
- package/dist/models/rules.js +12 -11
- package/dist/models/rules.js.map +1 -1
- package/dist/models/version.d.ts +13 -6
- package/dist/models/version.d.ts.map +1 -1
- package/dist/models/version.js +21 -15
- package/dist/models/version.js.map +1 -1
- package/package.json +1 -6
- package/src/index.ts +5 -63
- package/src/manager.ts +35 -0
- package/src/models/application.spec.ts +140 -54
- package/src/models/application.ts +61 -18
- package/src/models/rules.spec.ts +32 -25
- package/src/models/rules.ts +17 -12
- package/src/models/version.spec.ts +61 -53
- package/src/models/version.ts +39 -27
- package/src/index.spec.ts +0 -89
|
@@ -1,22 +1,28 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
|
|
1
|
+
import 'jest-dynalite/withDb';
|
|
2
|
+
import * as dynamodb from '@aws-sdk/client-dynamodb';
|
|
3
|
+
import { DBManager } from '../manager';
|
|
4
|
+
import { Version } from './version';
|
|
5
|
+
|
|
6
|
+
let dynamoClient: dynamodb.DynamoDBClient;
|
|
7
|
+
let dbManager: DBManager;
|
|
8
|
+
|
|
9
|
+
const TEST_TABLE_NAME = 'microapps';
|
|
6
10
|
|
|
7
11
|
describe('version records', () => {
|
|
8
|
-
|
|
9
|
-
new
|
|
10
|
-
|
|
12
|
+
beforeAll(() => {
|
|
13
|
+
dynamoClient = new dynamodb.DynamoDBClient({
|
|
14
|
+
endpoint: process.env.MOCK_DYNAMODB_ENDPOINT,
|
|
15
|
+
tls: false,
|
|
16
|
+
region: 'local',
|
|
17
|
+
});
|
|
11
18
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
await InitializeTable();
|
|
19
|
+
// Init the DB manager to point it at the right table
|
|
20
|
+
dbManager = new DBManager({ dynamoClient, tableName: TEST_TABLE_NAME });
|
|
15
21
|
});
|
|
16
22
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
});
|
|
23
|
+
afterAll(() => {
|
|
24
|
+
dynamoClient.destroy();
|
|
25
|
+
}, 20000);
|
|
20
26
|
|
|
21
27
|
it('saving a version should create one record', async () => {
|
|
22
28
|
const version = new Version();
|
|
@@ -27,20 +33,21 @@ describe('version records', () => {
|
|
|
27
33
|
version.DefaultFile = 'index.html';
|
|
28
34
|
version.IntegrationID = 'abcd';
|
|
29
35
|
|
|
30
|
-
await version.
|
|
36
|
+
await version.Save(dbManager);
|
|
31
37
|
|
|
32
|
-
const { Item } = await
|
|
33
|
-
TableName:
|
|
38
|
+
const { Item } = await dbManager.ddbDocClient.get({
|
|
39
|
+
TableName: dbManager.tableName,
|
|
34
40
|
Key: { PK: 'appname#cat', SK: 'version#1.2.3-beta4' },
|
|
35
41
|
});
|
|
36
|
-
expect(Item
|
|
37
|
-
expect(Item
|
|
38
|
-
expect(Item
|
|
39
|
-
expect(Item
|
|
40
|
-
expect(Item
|
|
41
|
-
expect(Item
|
|
42
|
-
expect(Item
|
|
43
|
-
expect(Item
|
|
42
|
+
expect(Item).toBeDefined();
|
|
43
|
+
expect(Item?.PK).toBe('appname#cat');
|
|
44
|
+
expect(Item?.SK).toBe('version#1.2.3-beta4');
|
|
45
|
+
expect(Item?.AppName).toBe('cat');
|
|
46
|
+
expect(Item?.SemVer).toBe('1.2.3-Beta4');
|
|
47
|
+
expect(Item?.Status).toBe('pending');
|
|
48
|
+
expect(Item?.Type).toBe('type');
|
|
49
|
+
expect(Item?.DefaultFile).toBe('index.html');
|
|
50
|
+
expect(Item?.IntegrationID).toBe('abcd');
|
|
44
51
|
});
|
|
45
52
|
|
|
46
53
|
it('load 1 version should load 1 version', async () => {
|
|
@@ -52,7 +59,7 @@ describe('version records', () => {
|
|
|
52
59
|
version.DefaultFile = 'index.html';
|
|
53
60
|
version.IntegrationID = 'abcd';
|
|
54
61
|
|
|
55
|
-
await version.
|
|
62
|
+
await version.Save(dbManager);
|
|
56
63
|
|
|
57
64
|
version = new Version();
|
|
58
65
|
version.AppName = 'Dog';
|
|
@@ -62,27 +69,28 @@ describe('version records', () => {
|
|
|
62
69
|
version.DefaultFile = 'index.html';
|
|
63
70
|
version.IntegrationID = 'abcd';
|
|
64
71
|
|
|
65
|
-
await version.
|
|
72
|
+
await version.Save(dbManager);
|
|
66
73
|
|
|
67
|
-
const version1 = await Version.
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
74
|
+
const version1 = await Version.LoadVersion({
|
|
75
|
+
dbManager,
|
|
76
|
+
key: {
|
|
77
|
+
AppName: 'Dog',
|
|
78
|
+
SemVer: '1.2.3-Beta5',
|
|
79
|
+
},
|
|
80
|
+
});
|
|
72
81
|
|
|
73
|
-
expect(version1.AppName).
|
|
74
|
-
expect(version1.SK).
|
|
75
|
-
expect(version1.SemVer).
|
|
82
|
+
expect(version1.AppName).toBe('dog');
|
|
83
|
+
expect(version1.SK).toBe('version#1.2.3-beta5');
|
|
84
|
+
expect(version1.SemVer).toBe('1.2.3-Beta5');
|
|
76
85
|
|
|
77
|
-
const version2 = await Version.
|
|
78
|
-
|
|
79
|
-
'Dog',
|
|
80
|
-
|
|
81
|
-
);
|
|
86
|
+
const version2 = await Version.LoadVersion({
|
|
87
|
+
dbManager,
|
|
88
|
+
key: { AppName: 'Dog', SemVer: '1.2.3-Beta6' },
|
|
89
|
+
});
|
|
82
90
|
|
|
83
|
-
expect(version2.AppName).
|
|
84
|
-
expect(version2.SK).
|
|
85
|
-
expect(version2.SemVer).
|
|
91
|
+
expect(version2.AppName).toBe('dog');
|
|
92
|
+
expect(version2.SK).toBe('version#1.2.3-beta6');
|
|
93
|
+
expect(version2.SemVer).toBe('1.2.3-Beta6');
|
|
86
94
|
});
|
|
87
95
|
|
|
88
96
|
it('load all app versions should load all versions for 1 app', async () => {
|
|
@@ -94,7 +102,7 @@ describe('version records', () => {
|
|
|
94
102
|
version.DefaultFile = 'index.html';
|
|
95
103
|
version.IntegrationID = 'abcd';
|
|
96
104
|
|
|
97
|
-
await version.
|
|
105
|
+
await version.Save(dbManager);
|
|
98
106
|
|
|
99
107
|
version = new Version();
|
|
100
108
|
version.AppName = 'Frog';
|
|
@@ -104,17 +112,17 @@ describe('version records', () => {
|
|
|
104
112
|
version.DefaultFile = 'index.html';
|
|
105
113
|
version.IntegrationID = 'abcd';
|
|
106
114
|
|
|
107
|
-
await version.
|
|
115
|
+
await version.Save(dbManager);
|
|
108
116
|
|
|
109
|
-
const versions = await Version.
|
|
117
|
+
const versions = await Version.LoadVersions({ dbManager, key: { AppName: 'Frog' } });
|
|
110
118
|
|
|
111
|
-
expect(versions.length).
|
|
119
|
+
expect(versions.length).toBe(2);
|
|
112
120
|
|
|
113
|
-
expect(versions[0].AppName).
|
|
114
|
-
expect(versions[0].SK).
|
|
115
|
-
expect(versions[0].SemVer).
|
|
116
|
-
expect(versions[1].AppName).
|
|
117
|
-
expect(versions[1].SK).
|
|
118
|
-
expect(versions[1].SemVer).
|
|
121
|
+
expect(versions[0].AppName).toBe('frog');
|
|
122
|
+
expect(versions[0].SK).toBe('version#2.2.3-beta5');
|
|
123
|
+
expect(versions[0].SemVer).toBe('2.2.3-Beta5');
|
|
124
|
+
expect(versions[1].AppName).toBe('frog');
|
|
125
|
+
expect(versions[1].SK).toBe('version#2.2.3-beta6');
|
|
126
|
+
expect(versions[1].SemVer).toBe('2.2.3-Beta6');
|
|
119
127
|
});
|
|
120
128
|
});
|
package/src/models/version.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { DynamoDBDocument } from '@aws-sdk/lib-dynamodb';
|
|
2
1
|
import { plainToClass } from 'class-transformer';
|
|
3
|
-
import {
|
|
2
|
+
import { DBManager } from '..';
|
|
4
3
|
|
|
5
4
|
enum SaveBy {
|
|
6
5
|
AppName,
|
|
@@ -25,16 +24,23 @@ export interface IVersionRecord {
|
|
|
25
24
|
IntegrationID: string;
|
|
26
25
|
}
|
|
27
26
|
|
|
28
|
-
export
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
export type IVersionRecordNoKeysLoose = Partial<
|
|
28
|
+
Omit<IVersionRecord, 'PK' | 'SK' | 'AppName' | 'SemVer'>
|
|
29
|
+
> &
|
|
30
|
+
Pick<IVersionRecord, 'AppName' | 'SemVer'>;
|
|
31
|
+
|
|
32
|
+
export class Version implements IVersionRecord {
|
|
33
|
+
public static async LoadVersions(opts: {
|
|
34
|
+
dbManager: DBManager;
|
|
35
|
+
key: Pick<IVersionRecord, 'AppName'>;
|
|
36
|
+
}): Promise<Version[]> {
|
|
37
|
+
const { dbManager, key } = opts;
|
|
38
|
+
|
|
39
|
+
const { Items } = await dbManager.ddbDocClient.query({
|
|
40
|
+
TableName: dbManager.tableName,
|
|
35
41
|
KeyConditionExpression: 'PK = :pkval and begins_with(SK, :skval)',
|
|
36
42
|
ExpressionAttributeValues: {
|
|
37
|
-
':pkval': `appName#${
|
|
43
|
+
':pkval': `appName#${key.AppName}`.toLowerCase(),
|
|
38
44
|
':skval': 'version',
|
|
39
45
|
},
|
|
40
46
|
});
|
|
@@ -49,16 +55,17 @@ export default class Version implements IVersionRecord {
|
|
|
49
55
|
return records;
|
|
50
56
|
}
|
|
51
57
|
|
|
52
|
-
public static async
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
58
|
+
public static async LoadVersion(opts: {
|
|
59
|
+
dbManager: DBManager;
|
|
60
|
+
key: Pick<IVersionRecord, 'AppName' | 'SemVer'>;
|
|
61
|
+
}): Promise<Version> {
|
|
62
|
+
const { dbManager, key } = opts;
|
|
63
|
+
|
|
64
|
+
const { Item } = await dbManager.ddbDocClient.get({
|
|
65
|
+
TableName: dbManager.tableName,
|
|
59
66
|
Key: {
|
|
60
|
-
PK: `appName#${
|
|
61
|
-
SK: `version#${
|
|
67
|
+
PK: `appName#${key.AppName}`.toLowerCase(),
|
|
68
|
+
SK: `version#${key.SemVer}`.toLowerCase(),
|
|
62
69
|
},
|
|
63
70
|
});
|
|
64
71
|
const record = plainToClass<Version, unknown>(Version, Item);
|
|
@@ -78,13 +85,18 @@ export default class Version implements IVersionRecord {
|
|
|
78
85
|
private _appName: string | undefined;
|
|
79
86
|
private _semVer: string | undefined;
|
|
80
87
|
private _type: string | undefined;
|
|
81
|
-
private _status: VersionStatus
|
|
82
|
-
private _defaultFile: string
|
|
83
|
-
private _integrationID: string
|
|
88
|
+
private _status: VersionStatus;
|
|
89
|
+
private _defaultFile: string;
|
|
90
|
+
private _integrationID: string;
|
|
84
91
|
|
|
85
|
-
public constructor(init?: Partial<
|
|
86
|
-
Object.assign(this, init);
|
|
92
|
+
public constructor(init?: Partial<IVersionRecordNoKeysLoose>) {
|
|
87
93
|
this._keyBy = SaveBy.AppName;
|
|
94
|
+
this._status = 'pending';
|
|
95
|
+
this._defaultFile = '';
|
|
96
|
+
this._integrationID = '';
|
|
97
|
+
|
|
98
|
+
// Save any passed in values over the defaults
|
|
99
|
+
Object.assign(this, init);
|
|
88
100
|
}
|
|
89
101
|
|
|
90
102
|
public get DbStruct(): IVersionRecord {
|
|
@@ -100,13 +112,13 @@ export default class Version implements IVersionRecord {
|
|
|
100
112
|
};
|
|
101
113
|
}
|
|
102
114
|
|
|
103
|
-
public async
|
|
115
|
+
public async Save(dbManager: DBManager): Promise<void> {
|
|
104
116
|
// TODO: Validate that all the fields needed are present
|
|
105
117
|
|
|
106
118
|
// Save under specific AppName key
|
|
107
119
|
this._keyBy = SaveBy.AppName;
|
|
108
|
-
await ddbDocClient.put({
|
|
109
|
-
TableName:
|
|
120
|
+
await dbManager.ddbDocClient.put({
|
|
121
|
+
TableName: dbManager.tableName,
|
|
110
122
|
Item: this.DbStruct,
|
|
111
123
|
});
|
|
112
124
|
}
|
package/src/index.spec.ts
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { expect } from 'chai';
|
|
2
|
-
import { describe, it } from 'mocha';
|
|
3
|
-
import { dynamoClient, InitializeTable, DropTable, TEST_TABLE_NAME } from '../../../fixtures';
|
|
4
|
-
import Manager, { Application, Version, Rules } from './index';
|
|
5
|
-
|
|
6
|
-
describe('database manager', () => {
|
|
7
|
-
before(async () => {
|
|
8
|
-
new Manager({ dynamoDB: dynamoClient.client, tableName: TEST_TABLE_NAME });
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
beforeEach(async () => {
|
|
12
|
-
// Create the table
|
|
13
|
-
await InitializeTable();
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
afterEach(async () => {
|
|
17
|
-
await DropTable();
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('should get versions and rules when asked', async () => {
|
|
21
|
-
const app = new Application({
|
|
22
|
-
AppName: 'Bat',
|
|
23
|
-
DisplayName: 'Bat App',
|
|
24
|
-
});
|
|
25
|
-
await app.SaveAsync(dynamoClient.ddbDocClient);
|
|
26
|
-
|
|
27
|
-
const version = new Version({
|
|
28
|
-
AppName: 'Bat',
|
|
29
|
-
DefaultFile: 'bat.html',
|
|
30
|
-
IntegrationID: 'abcd',
|
|
31
|
-
SemVer: '3.2.1-beta0',
|
|
32
|
-
Status: 'deployed',
|
|
33
|
-
Type: 'next.js',
|
|
34
|
-
});
|
|
35
|
-
await version.SaveAsync(dynamoClient.ddbDocClient);
|
|
36
|
-
|
|
37
|
-
const rules = new Rules({
|
|
38
|
-
AppName: 'Bat',
|
|
39
|
-
Version: 0,
|
|
40
|
-
RuleSet: { default: { SemVer: '3.2.1-beta0', AttributeName: '', AttributeValue: '' } },
|
|
41
|
-
});
|
|
42
|
-
await rules.SaveAsync(dynamoClient.ddbDocClient);
|
|
43
|
-
|
|
44
|
-
const versAndRules = await Manager.GetVersionsAndRules('bat');
|
|
45
|
-
|
|
46
|
-
expect(versAndRules).to.have.property('Versions');
|
|
47
|
-
expect(versAndRules).to.have.property('Rules');
|
|
48
|
-
expect(versAndRules.Rules).to.have.property('RuleSet');
|
|
49
|
-
expect(versAndRules.Rules.RuleSet).to.have.property('default');
|
|
50
|
-
expect(versAndRules.Rules.RuleSet.default).to.have.property('SemVer');
|
|
51
|
-
expect(versAndRules.Rules.RuleSet.default.SemVer).to.equal('3.2.1-beta0');
|
|
52
|
-
expect(versAndRules.Versions.length).to.equal(1);
|
|
53
|
-
expect(versAndRules.Versions[0].SemVer).to.equal('3.2.1-beta0');
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('should update default rule', async () => {
|
|
57
|
-
const app = new Application({
|
|
58
|
-
AppName: 'Bat2',
|
|
59
|
-
DisplayName: 'Bat App',
|
|
60
|
-
});
|
|
61
|
-
await app.SaveAsync(dynamoClient.ddbDocClient);
|
|
62
|
-
|
|
63
|
-
const version = new Version({
|
|
64
|
-
AppName: 'Bat2',
|
|
65
|
-
DefaultFile: 'bat.html',
|
|
66
|
-
IntegrationID: 'abcd',
|
|
67
|
-
SemVer: '3.2.1-beta0',
|
|
68
|
-
Status: 'deployed',
|
|
69
|
-
Type: 'next.js',
|
|
70
|
-
});
|
|
71
|
-
await version.SaveAsync(dynamoClient.ddbDocClient);
|
|
72
|
-
|
|
73
|
-
const rules = new Rules({
|
|
74
|
-
AppName: 'Bat2',
|
|
75
|
-
Version: 0,
|
|
76
|
-
RuleSet: { default: { SemVer: '3.2.1-beta0', AttributeName: '', AttributeValue: '' } },
|
|
77
|
-
});
|
|
78
|
-
await rules.SaveAsync(dynamoClient.ddbDocClient);
|
|
79
|
-
|
|
80
|
-
// Check version before update
|
|
81
|
-
let versAndRules = await Manager.GetVersionsAndRules('bat2');
|
|
82
|
-
expect(versAndRules.Rules.RuleSet.default.SemVer).to.equal('3.2.1-beta0');
|
|
83
|
-
|
|
84
|
-
// Update default version
|
|
85
|
-
await Manager.UpdateDefaultRule('bat2', '3.2.2');
|
|
86
|
-
versAndRules = await Manager.GetVersionsAndRules('bat2');
|
|
87
|
-
expect(versAndRules.Rules.RuleSet.default.SemVer).to.equal('3.2.2');
|
|
88
|
-
});
|
|
89
|
-
});
|