@feathersjs/feathers 5.0.0-pre.25 → 5.0.0-pre.28
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/CHANGELOG.md +28 -0
- package/lib/hooks.d.ts +24 -3
- package/lib/hooks.js +38 -50
- package/lib/hooks.js.map +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +8 -7
- package/src/hooks.ts +58 -73
- package/src/version.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,34 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [5.0.0-pre.28](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.27...v5.0.0-pre.28) (2022-08-03)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **cli:** Improve generated application and client ([#2701](https://github.com/feathersjs/feathers/issues/2701)) ([bd55ffb](https://github.com/feathersjs/feathers/commit/bd55ffb812e89bf215f4515e7f137656ea888c3f))
|
|
12
|
+
* **core:** Get hooks to work reliably with custom methods ([#2714](https://github.com/feathersjs/feathers/issues/2714)) ([8d7e04a](https://github.com/feathersjs/feathers/commit/8d7e04acd0f0e2af9f4c13efee652d296dd3bc51))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
# [5.0.0-pre.27](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.26...v5.0.0-pre.27) (2022-07-13)
|
|
19
|
+
|
|
20
|
+
**Note:** Version bump only for package @feathersjs/feathers
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
# [5.0.0-pre.26](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.25...v5.0.0-pre.26) (2022-06-22)
|
|
27
|
+
|
|
28
|
+
**Note:** Version bump only for package @feathersjs/feathers
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
6
34
|
# [5.0.0-pre.25](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.24...v5.0.0-pre.25) (2022-06-22)
|
|
7
35
|
|
|
8
36
|
**Note:** Version bump only for package @feathersjs/feathers
|
package/lib/hooks.d.ts
CHANGED
|
@@ -1,10 +1,30 @@
|
|
|
1
1
|
import { HookContextData, HookManager, Middleware } from '@feathersjs/hooks';
|
|
2
2
|
import { Service, ServiceOptions, HookContext, FeathersService, HookMap, AroundHookFunction, HookFunction } from './declarations';
|
|
3
|
-
|
|
3
|
+
declare type HookStore = {
|
|
4
|
+
around: {
|
|
5
|
+
[method: string]: AroundHookFunction[];
|
|
6
|
+
};
|
|
7
|
+
before: {
|
|
8
|
+
[method: string]: HookFunction[];
|
|
9
|
+
};
|
|
10
|
+
after: {
|
|
11
|
+
[method: string]: HookFunction[];
|
|
12
|
+
};
|
|
13
|
+
error: {
|
|
14
|
+
[method: string]: HookFunction[];
|
|
15
|
+
};
|
|
16
|
+
collected: {
|
|
17
|
+
[method: string]: AroundHookFunction[];
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
declare type HookEnabled = {
|
|
21
|
+
__hooks: HookStore;
|
|
22
|
+
};
|
|
4
23
|
export declare function convertHookData(input: any): {
|
|
5
|
-
[method: string]:
|
|
24
|
+
[method: string]: AroundHookFunction<import("./declarations").Application<any, any>, Service<any, Partial<any>, import("./declarations").Params<import("./declarations").Query>>>[] | HookFunction<import("./declarations").Application<any, any>, Service<any, Partial<any>, import("./declarations").Params<import("./declarations").Query>>>[];
|
|
6
25
|
};
|
|
7
|
-
export declare function
|
|
26
|
+
export declare function collectHooks(target: HookEnabled, method: string): AroundHookFunction<import("./declarations").Application<any, any>, Service<any, Partial<any>, import("./declarations").Params<import("./declarations").Query>>>[];
|
|
27
|
+
export declare function enableHooks(object: any): (this: HookEnabled, input: HookMap<any, any>) => HookEnabled;
|
|
8
28
|
export declare function createContext(service: Service, method: string, data?: HookContextData): HookContext<import("./declarations").Application<any, any>, any>;
|
|
9
29
|
export declare class FeathersHookManager<A> extends HookManager {
|
|
10
30
|
app: A;
|
|
@@ -15,3 +35,4 @@ export declare class FeathersHookManager<A> extends HookManager {
|
|
|
15
35
|
middleware(mw: Middleware[]): this;
|
|
16
36
|
}
|
|
17
37
|
export declare function hookMixin<A>(this: A, service: FeathersService<A>, path: string, options: ServiceOptions): FeathersService<A, Service<any, Partial<any>, import("./declarations").Params<import("./declarations").Query>>>;
|
|
38
|
+
export {};
|
package/lib/hooks.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.hookMixin = exports.FeathersHookManager = exports.createContext = exports.enableHooks = exports.
|
|
3
|
+
exports.hookMixin = exports.FeathersHookManager = exports.createContext = exports.enableHooks = exports.collectHooks = exports.convertHookData = void 0;
|
|
4
4
|
const hooks_1 = require("@feathersjs/hooks");
|
|
5
5
|
const service_1 = require("./service");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
exports.collectHooks = collectHooks;
|
|
6
|
+
const types = ['before', 'after', 'error', 'around'];
|
|
7
|
+
const isType = (value) => types.includes(value);
|
|
10
8
|
// Converts different hook registration formats into the
|
|
11
9
|
// same internal format
|
|
12
10
|
function convertHookData(input) {
|
|
@@ -26,55 +24,25 @@ function convertHookData(input) {
|
|
|
26
24
|
return result;
|
|
27
25
|
}
|
|
28
26
|
exports.convertHookData = convertHookData;
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if (method !== 'all' && !methods.includes(method) && !service_1.defaultServiceMethods.includes(method)) {
|
|
40
|
-
throw new Error(`'${method}' is not a valid hook method`);
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
map[type] = data;
|
|
44
|
-
});
|
|
45
|
-
return map;
|
|
46
|
-
};
|
|
47
|
-
const updateStore = (store, map) => Object.keys(store.hooks).forEach((method) => {
|
|
48
|
-
Object.keys(map).forEach((key) => {
|
|
49
|
-
var _a;
|
|
50
|
-
const type = key;
|
|
51
|
-
const allHooks = map[type].all || [];
|
|
52
|
-
const methodHooks = map[type][method] || [];
|
|
53
|
-
if (allHooks.length || methodHooks.length) {
|
|
54
|
-
const list = [...allHooks, ...methodHooks];
|
|
55
|
-
const hooks = ((_a = store[type])[method] || (_a[method] = []));
|
|
56
|
-
hooks.push(...list);
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
const collected = (0, hooks_1.collect)({
|
|
60
|
-
before: store.before[method] || [],
|
|
61
|
-
after: store.after[method] || [],
|
|
62
|
-
error: store.error[method] || []
|
|
63
|
-
});
|
|
64
|
-
store.hooks[method] = [...(store.around[method] || []), collected];
|
|
65
|
-
});
|
|
27
|
+
function collectHooks(target, method) {
|
|
28
|
+
const { collected, around } = target.__hooks;
|
|
29
|
+
return [
|
|
30
|
+
...(around.all || []),
|
|
31
|
+
...(around[method] || []),
|
|
32
|
+
...(collected.all || []),
|
|
33
|
+
...(collected[method] || [])
|
|
34
|
+
];
|
|
35
|
+
}
|
|
36
|
+
exports.collectHooks = collectHooks;
|
|
66
37
|
// Add `.hooks` functionality to an object
|
|
67
|
-
function enableHooks(object
|
|
38
|
+
function enableHooks(object) {
|
|
68
39
|
const store = {
|
|
69
40
|
around: {},
|
|
70
41
|
before: {},
|
|
71
42
|
after: {},
|
|
72
43
|
error: {},
|
|
73
|
-
|
|
44
|
+
collected: {}
|
|
74
45
|
};
|
|
75
|
-
for (const method of methods) {
|
|
76
|
-
store.hooks[method] = [];
|
|
77
|
-
}
|
|
78
46
|
Object.defineProperty(object, '__hooks', {
|
|
79
47
|
configurable: true,
|
|
80
48
|
value: store,
|
|
@@ -82,8 +50,28 @@ function enableHooks(object, methods = service_1.defaultServiceMethods) {
|
|
|
82
50
|
});
|
|
83
51
|
return function registerHooks(input) {
|
|
84
52
|
const store = this.__hooks;
|
|
85
|
-
const map =
|
|
86
|
-
|
|
53
|
+
const map = Object.keys(input).reduce((map, type) => {
|
|
54
|
+
if (!isType(type)) {
|
|
55
|
+
throw new Error(`'${type}' is not a valid hook type`);
|
|
56
|
+
}
|
|
57
|
+
map[type] = convertHookData(input[type]);
|
|
58
|
+
return map;
|
|
59
|
+
}, {});
|
|
60
|
+
const types = Object.keys(map);
|
|
61
|
+
types.forEach((type) => Object.keys(map[type]).forEach((method) => {
|
|
62
|
+
var _a;
|
|
63
|
+
const mapHooks = map[type][method];
|
|
64
|
+
const storeHooks = ((_a = store[type])[method] || (_a[method] = []));
|
|
65
|
+
storeHooks.push(...mapHooks);
|
|
66
|
+
if (store.before[method] || store.after[method] || store.error[method]) {
|
|
67
|
+
const collected = (0, hooks_1.collect)({
|
|
68
|
+
before: store.before[method] || [],
|
|
69
|
+
after: store.after[method] || [],
|
|
70
|
+
error: store.error[method] || []
|
|
71
|
+
});
|
|
72
|
+
store.collected[method] = [collected];
|
|
73
|
+
}
|
|
74
|
+
}));
|
|
87
75
|
return this;
|
|
88
76
|
};
|
|
89
77
|
}
|
|
@@ -145,7 +133,7 @@ function hookMixin(service, path, options) {
|
|
|
145
133
|
});
|
|
146
134
|
return res;
|
|
147
135
|
}, {});
|
|
148
|
-
const registerHooks = enableHooks(service
|
|
136
|
+
const registerHooks = enableHooks(service);
|
|
149
137
|
(0, hooks_1.hooks)(service, serviceMethodHooks);
|
|
150
138
|
service.hooks = function (hookOptions) {
|
|
151
139
|
if (hookOptions.before || hookOptions.after || hookOptions.error || hookOptions.around) {
|
package/lib/hooks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":";;;AA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AAM,iDAAiD,CAAC,CAAA;aACnF;YAED,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAA;QACzC,CAAC,CAAC,CAAA;QAEF,OAAO,IAAI,CAAA;IACb,CAAC,CAAA;IAED,OAAO,OAAO,CAAA;AAChB,CAAC;AAxDD,8BAwDC"}
|
package/lib/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "5.0.0-pre.
|
|
1
|
+
declare const _default: "5.0.0-pre.28";
|
|
2
2
|
export default _default;
|
package/lib/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@feathersjs/feathers",
|
|
3
3
|
"description": "A framework for real-time applications and REST API with JavaScript and TypeScript",
|
|
4
|
-
"version": "5.0.0-pre.
|
|
4
|
+
"version": "5.0.0-pre.28",
|
|
5
5
|
"homepage": "http://feathersjs.com",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -47,7 +47,8 @@
|
|
|
47
47
|
"prepublish": "npm run compile",
|
|
48
48
|
"version": "npm run write-version",
|
|
49
49
|
"publish": "npm run reset-version",
|
|
50
|
-
"
|
|
50
|
+
"pack": "npm pack --pack-destination ../cli/test",
|
|
51
|
+
"compile": "shx rm -rf lib/ && tsc && npm run pack",
|
|
51
52
|
"test": "mocha --config ../../.mocharc.json --recursive test/"
|
|
52
53
|
},
|
|
53
54
|
"engines": {
|
|
@@ -57,17 +58,17 @@
|
|
|
57
58
|
"access": "public"
|
|
58
59
|
},
|
|
59
60
|
"dependencies": {
|
|
60
|
-
"@feathersjs/commons": "^5.0.0-pre.
|
|
61
|
+
"@feathersjs/commons": "^5.0.0-pre.28",
|
|
61
62
|
"@feathersjs/hooks": "^0.7.5",
|
|
62
63
|
"events": "^3.3.0"
|
|
63
64
|
},
|
|
64
65
|
"devDependencies": {
|
|
65
66
|
"@types/mocha": "^9.1.1",
|
|
66
|
-
"@types/node": "^
|
|
67
|
+
"@types/node": "^18.6.3",
|
|
67
68
|
"mocha": "^10.0.0",
|
|
68
69
|
"shx": "^0.3.4",
|
|
69
|
-
"ts-node": "^10.
|
|
70
|
-
"typescript": "^4.7.
|
|
70
|
+
"ts-node": "^10.9.1",
|
|
71
|
+
"typescript": "^4.7.4"
|
|
71
72
|
},
|
|
72
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "bf8e54fddc14d688ba8f505e72c9630a71656ff1"
|
|
73
74
|
}
|
package/src/hooks.ts
CHANGED
|
@@ -16,12 +16,26 @@ import {
|
|
|
16
16
|
AroundHookFunction,
|
|
17
17
|
HookFunction
|
|
18
18
|
} from './declarations'
|
|
19
|
-
import { defaultServiceArguments,
|
|
19
|
+
import { defaultServiceArguments, getHookMethods } from './service'
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
type HookType = 'before' | 'after' | 'error' | 'around'
|
|
22
|
+
|
|
23
|
+
type ConvertedMap = { [type in HookType]: ReturnType<typeof convertHookData> }
|
|
24
|
+
|
|
25
|
+
type HookStore = {
|
|
26
|
+
around: { [method: string]: AroundHookFunction[] }
|
|
27
|
+
before: { [method: string]: HookFunction[] }
|
|
28
|
+
after: { [method: string]: HookFunction[] }
|
|
29
|
+
error: { [method: string]: HookFunction[] }
|
|
30
|
+
collected: { [method: string]: AroundHookFunction[] }
|
|
23
31
|
}
|
|
24
32
|
|
|
33
|
+
type HookEnabled = { __hooks: HookStore }
|
|
34
|
+
|
|
35
|
+
const types: HookType[] = ['before', 'after', 'error', 'around']
|
|
36
|
+
|
|
37
|
+
const isType = (value: any): value is HookType => types.includes(value)
|
|
38
|
+
|
|
25
39
|
// Converts different hook registration formats into the
|
|
26
40
|
// same internal format
|
|
27
41
|
export function convertHookData(input: any) {
|
|
@@ -41,80 +55,25 @@ export function convertHookData(input: any) {
|
|
|
41
55
|
return result
|
|
42
56
|
}
|
|
43
57
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
type ConvertedMap = { [type in HookTypes]: ReturnType<typeof convertHookData> }
|
|
47
|
-
|
|
48
|
-
type HookStore = {
|
|
49
|
-
around: { [method: string]: AroundHookFunction[] }
|
|
50
|
-
before: { [method: string]: HookFunction[] }
|
|
51
|
-
after: { [method: string]: HookFunction[] }
|
|
52
|
-
error: { [method: string]: HookFunction[] }
|
|
53
|
-
hooks: { [method: string]: AroundHookFunction[] }
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const types: HookTypes[] = ['before', 'after', 'error', 'around']
|
|
57
|
-
|
|
58
|
-
const isType = (value: any): value is HookTypes => types.includes(value)
|
|
59
|
-
|
|
60
|
-
const createMap = (input: HookMap<any, any>, methods: string[]) => {
|
|
61
|
-
const map = {} as ConvertedMap
|
|
62
|
-
|
|
63
|
-
Object.keys(input).forEach((type) => {
|
|
64
|
-
if (!isType(type)) {
|
|
65
|
-
throw new Error(`'${type}' is not a valid hook type`)
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const data = convertHookData(input[type])
|
|
69
|
-
|
|
70
|
-
Object.keys(data).forEach((method) => {
|
|
71
|
-
if (method !== 'all' && !methods.includes(method) && !defaultServiceMethods.includes(method)) {
|
|
72
|
-
throw new Error(`'${method}' is not a valid hook method`)
|
|
73
|
-
}
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
map[type] = data
|
|
77
|
-
})
|
|
58
|
+
export function collectHooks(target: HookEnabled, method: string) {
|
|
59
|
+
const { collected, around } = target.__hooks
|
|
78
60
|
|
|
79
|
-
return
|
|
61
|
+
return [
|
|
62
|
+
...(around.all || []),
|
|
63
|
+
...(around[method] || []),
|
|
64
|
+
...(collected.all || []),
|
|
65
|
+
...(collected[method] || [])
|
|
66
|
+
] as AroundHookFunction[]
|
|
80
67
|
}
|
|
81
68
|
|
|
82
|
-
const updateStore = (store: HookStore, map: ConvertedMap) =>
|
|
83
|
-
Object.keys(store.hooks).forEach((method) => {
|
|
84
|
-
Object.keys(map).forEach((key) => {
|
|
85
|
-
const type = key as HookTypes
|
|
86
|
-
const allHooks = map[type].all || []
|
|
87
|
-
const methodHooks = map[type][method] || []
|
|
88
|
-
|
|
89
|
-
if (allHooks.length || methodHooks.length) {
|
|
90
|
-
const list = [...allHooks, ...methodHooks] as any
|
|
91
|
-
const hooks = (store[type][method] ||= [])
|
|
92
|
-
|
|
93
|
-
hooks.push(...list)
|
|
94
|
-
}
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
const collected = collect({
|
|
98
|
-
before: store.before[method] || [],
|
|
99
|
-
after: store.after[method] || [],
|
|
100
|
-
error: store.error[method] || []
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
store.hooks[method] = [...(store.around[method] || []), collected]
|
|
104
|
-
})
|
|
105
|
-
|
|
106
69
|
// Add `.hooks` functionality to an object
|
|
107
|
-
export function enableHooks(object: any
|
|
70
|
+
export function enableHooks(object: any) {
|
|
108
71
|
const store: HookStore = {
|
|
109
72
|
around: {},
|
|
110
73
|
before: {},
|
|
111
74
|
after: {},
|
|
112
75
|
error: {},
|
|
113
|
-
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
for (const method of methods) {
|
|
117
|
-
store.hooks[method] = []
|
|
76
|
+
collected: {}
|
|
118
77
|
}
|
|
119
78
|
|
|
120
79
|
Object.defineProperty(object, '__hooks', {
|
|
@@ -123,11 +82,37 @@ export function enableHooks(object: any, methods: string[] = defaultServiceMetho
|
|
|
123
82
|
writable: true
|
|
124
83
|
})
|
|
125
84
|
|
|
126
|
-
return function registerHooks(this:
|
|
85
|
+
return function registerHooks(this: HookEnabled, input: HookMap<any, any>) {
|
|
127
86
|
const store = this.__hooks
|
|
128
|
-
const map =
|
|
87
|
+
const map = Object.keys(input).reduce((map, type) => {
|
|
88
|
+
if (!isType(type)) {
|
|
89
|
+
throw new Error(`'${type}' is not a valid hook type`)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
map[type] = convertHookData(input[type])
|
|
93
|
+
|
|
94
|
+
return map
|
|
95
|
+
}, {} as ConvertedMap)
|
|
96
|
+
const types = Object.keys(map) as HookType[]
|
|
97
|
+
|
|
98
|
+
types.forEach((type) =>
|
|
99
|
+
Object.keys(map[type]).forEach((method) => {
|
|
100
|
+
const mapHooks = map[type][method]
|
|
101
|
+
const storeHooks: any[] = (store[type][method] ||= [])
|
|
102
|
+
|
|
103
|
+
storeHooks.push(...mapHooks)
|
|
104
|
+
|
|
105
|
+
if (store.before[method] || store.after[method] || store.error[method]) {
|
|
106
|
+
const collected = collect({
|
|
107
|
+
before: store.before[method] || [],
|
|
108
|
+
after: store.after[method] || [],
|
|
109
|
+
error: store.error[method] || []
|
|
110
|
+
})
|
|
129
111
|
|
|
130
|
-
|
|
112
|
+
store.collected[method] = [collected]
|
|
113
|
+
}
|
|
114
|
+
})
|
|
115
|
+
)
|
|
131
116
|
|
|
132
117
|
return this
|
|
133
118
|
}
|
|
@@ -150,7 +135,7 @@ export class FeathersHookManager<A> extends HookManager {
|
|
|
150
135
|
}
|
|
151
136
|
|
|
152
137
|
collectMiddleware(self: any, args: any[]): Middleware[] {
|
|
153
|
-
const appHooks = collectHooks(this.app, this.method)
|
|
138
|
+
const appHooks = collectHooks(this.app as any as HookEnabled, this.method)
|
|
154
139
|
const middleware = super.collectMiddleware(self, args)
|
|
155
140
|
const methodHooks = collectHooks(self, this.method)
|
|
156
141
|
|
|
@@ -200,7 +185,7 @@ export function hookMixin<A>(this: A, service: FeathersService<A>, path: string,
|
|
|
200
185
|
return res
|
|
201
186
|
}, {} as BaseHookMap)
|
|
202
187
|
|
|
203
|
-
const registerHooks = enableHooks(service
|
|
188
|
+
const registerHooks = enableHooks(service)
|
|
204
189
|
|
|
205
190
|
hooks(service, serviceMethodHooks)
|
|
206
191
|
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '5.0.0-pre.
|
|
1
|
+
export default '5.0.0-pre.28'
|